格林模拟试题二参考答案(3)
添加时间: 2007-9-22 6:52:10 作者: JAVA认证考试 阅读次数:48 来源: http://www.d9soft.com
Answer 43)
2) Ask for a re-design of the hierarchy with changing the Operating System to a field rather than Class type
This question is about the requirement to understand the difference between the "is-a" and the "has-a" relationship. Where a class is inherited you have to ask if it represents the "is-a" relationship. As the difference between the root and the two children are the operating system you need to ask are Linux and Windows types of computers.The answer is no, they are both types of Operating Systems. So option two represents the best of the options. You might consider having operating system as an interface instead but that is another story.
Of course there are as many ways to design an object hierarchy as ways to pronounce Bjarne Strousjoup, but this is the sort of answer that Sun will proabably be looking for in the exam. Questions have been asked in discussion forums if this type of question really comes up in the exam. I think this is because some other mock exams do not contain any questions like this. I assure you that this type of question can come up in the exam. These types of question are testing your understanding of the difference between the is-a and has-a relationship in class design.
Answer 44)
1) An inner class may be defined as static
4) An inner class may extend another class
A static inner class is also sometimes known as a top level nested class. There is some debate if such a class should be called an inner class. I tend to think it should be on the basis that it is created inside the opening braces of another class. How could a programmer provide a constructor for an anonymous class?. Remember a constructor is a method with no return type and the same name as the class. Inner classes may be defined as private
Answer 45)
4) Compilation and output of "Not equal! 10"
The output will be "Not equal 10". This illustrates that the Output +=10 calculation was never performed because processing stopped after the first operand was evaluated to be false. If you change the value of b1 to true processing occurs as you would expect and the output is "We are equal 20";.
Answer 46)
2)j= i<<j;4)j=i<<l;
Answer 47)
4) 12
As well as the binary OR objective this questions requires you to understand the octal notation which means that the leading letter zero (not the letter O)) means that the first 1 indicates the number contains one eight and nothing else. Thus this calculation in decimal mean
84To convert this to binary means
10000100----1100----Which is 12 in decimal
The bitwise operator means that for each position where there is a 1, results in a 1 in the same position in the answer.
Answer 48)
2)s+=i;
Only a String acts as if the + operator were overloaded
Answer 49)
Although the objectives do not specifically mention the need to understand the I/O Classes, feedback from people who have taken the exam indicate that you will get questions on this topic. As you will probably need to know this in the real world of Java programming, get familiar with the basics. I have assigned these questions to Objective 10.1 as that is a fairly vague objective.
1) File f = new File("/","autoexec.bat");
2) DataInputStream d = new DataInputStream(System.in);
3) OutputStreamWriter o = new OutputStreamWriter(System.out);
Option 4, with the RandomAccess file will not compile because the constructor must also be passed a mode parameter which must be either "r" or "rw"
Answer 50)
1)o1=o2;2)b=ob;4)o1=b;
Answer 51)
4) 10020
In the call
another(v,i);
A reference to v is passed and thus any changes will be intact after this call.
Answer 52)
1) public void amethod(String s, int i){}
4) public void Amethod(int i, String s) {}
Overloaded methods are differentiated only on the number, type and order of parameters, not on the return type of the method or the names of the parameters.
Answer 53)
4)Base b = new Base(10);
Any call to this or super must be the first line in a constructor. As the method already has a call to this, no more can be inserted.
Answer 54)
1) System.out.println(s);
4) System.out.println(iArgs);
A class within a method can only see final variables of the enclosing method. However it the normal visibility rules apply for variables outside the enclosing method.
Answer 55)
1) yield()
2) sleep
4) stop()
Note, the methods stop and suspend have been deprecated with the Java 2 release, and you may get questions on the exam that expect you to know this. Check out the Java2 Docs for an explanation
Answer 56)
1) addElement
Answer 57)
The import statement allows you to use a class directly instead of fully qualifying it with the full package name, adding more classess with the import statement does not cause a runtime performance overhad. I assure you this is true. An inner class can be defined with the protected modifier, though I am not certain why you would want to do it. An inner class can be defined with the private modifier, try compiling some sample code before emailing me to ask about this.
3)A inner class may under some circumstances be defined with the protected modifier
4) An interface cannot be instantiated
Answer 58)
1) mousePressed(MouseEvent e){}
4) componentAdded(ContainerEvent e){}
Answer 59)
1) iterator
2) isEmpty
3) toArray
Answer 60)
2) Ensures only one thread at a time may access a method or object
End of document
上一篇文章: 格林模拟试题二参考答案(2) 下一篇文章: 格林模拟试题三参考答案(1)

