格林模拟试题三参考答案(2)
添加时间: 2007-9-22 7:18:43 作者: JAVA认证考试 阅读次数:30 来源: http://www.d9soft.com
Answer to Question 17)
1) static methods do not have access to the implicit variable called this
2) A static method may be called without creating an instance of its class
3) a static may not be overriden to be non-static
The implicit variable this refers to the current instance of a class and thus and by its nature a static method cannot have access to it.
For more information on this topic go to
Answer to Question 18)
1)
char c='1';
System.out.println(c>>1);
4)
int i=1;
System.out.println(i<<1);
Be aware that Integer (not the upper case I) is a wrapper class and thus cannot be treated like a primitive. The fact that option 1 will compile may be a surprise, but although the char type is normally used to store character types, it is actually an unsigned integer type. The reason option 3 does not compile is that Java has a >>> operator but not a <<< operator. ;>> operator but not a <<< operator.
For more information on this topic go to
Answer to Question 19)
2) An event listener may be removed from a component
3) The ActionListener interface has no corresponding Adapter class
A component may have multiple event listeners attached. Thus a field may need to respond to both the mouse and the keyboard, requiring multiple event handlers. The ActionListener has not matching Adapter class because it has only one method, the idea of the Adapter classes is to eliminate the need to create blank methods.
For more information on this topic go to
Answer to Question 20)
3) transient
4) volatile
Option 1, sizeof is designed to catch out the C/C++ programmers. Java does not have a sizeof keyword as the size of primitives should be consistent on all Java implementations. Although a program needs a main method with the standard signature to start up it is not a keyword. The real keywords are less commonly used and therefore might not be so familiar to you.
For more information on this topic go to
Answer to Question 21)
3) The default constructor takes no parameters
4) The default constructor is not created if the class has any constructors of its own.
Option 1 is fairly obviously wrong as constructors never have a return type. Option 2 is very dubious as well as Java does not offer void as a type for a method or constructor.
For more information on this topic go to
Answer to Question 22)
1) All of the variables in an interface are implicitly static
2) All of the variables in an interface are implicitly final
3) All of the methods in an interface are implictly abstract
All the variables in an interface are implicitly static and final. Any methods in an interface have no body, so may not access any type of variable
Answer to Question 23)
2) The + operator is overloaded for concatenation for the String class
In Java Strings are implemented as a class within the Java.lang package with the special distinction that the + operator is overloaded. If you thought that the String class is implemented as a char array, you may have a head full of C/++ that needs emptying. There is not "wrapper class" for String as wrappers are only for primitive types.
If you are surprised that option 4 is not a correct answer it is because length is a method for the String class, but a property for and array and it is easy to get the two confused.
Answer to Question 24)
1) A method in an interface must not have a body
3) A class may extends one other class plus many interfaces
A class accesses an interface using the implements keyword (not uses)
Answer to Question 25)
3) The following statement will produce a result of zero, System.out.println(1 >>1);
Although you might not know the exact result of the operation -1 >>> 2 a knowledge of the way the bits will be shifted will tell you that the result is not plus 1. (The result is more like 1073741823 ) There is no such Java operator as the unsigned left shift. Although it is normally used for storing characters rather than numbers the char Java primitive is actually an unsigned integer type.
And for information on the size of primitives see
Answer to Question 26)
2) Arrays elements are initialized to default values wherever they are created using the keyword new.
You can find the size of an array using the length field. The method length is used to return the number of characters in a String. An array can contain elements of any type but they must all be of the same type. The size of an array is fixed at creation. If you want to change its size you can of course create a new array and assign the old one to it. A more flexible approach can be to use a collection class such as Vector.
Answer to Question 27)
2) Output of "Hello Crowle"
This code is an example of a short circuited operator. Because the first operand of the (or) operator returns true Java sees no reason to evaluate the second. Whatever the value of the second the overall result will always be true. Thus the method called place is never called.
Answer to Question 28)
4) none of the above;
You may access methods of a direct parent class through the use of super but classes further up the hierarchy are not visible
Answer to Question 29)
2) A method with the same name completly replaces the functionality of a method earlier in the hierarchy
Option 3 is more like a description of overloading. I like to remind myself of the difference between overloading and overriding in that an overriden method is like something overriden in the road, it is squashed, flat no longer used and replaced by something else. An overloaded method has been given extra work to do (it is loaded up with work), but it is still being used in its original format. This is just my little mind trick and doesn't match to anything that Java is doing.
Answer to Question 30)
2) The / operator is used to divide one value by another
3) The # symbol may not be used as the first character of a variable
The % is the modulo operator and returns the remainder after a division. Thus 10 % 3=1
The $ symbol may be used as the first character of a variable, but I would suggest that it is generally not a good idea. The # symbol cannot be used anywhere in the name of a variable. Knowing if a variable can start with the # or $ characters may seem like arbitrary and non essential knowlege but questions like this do come up on the exam.
Answer to Question 31)
1) The default layout manager for an Applet is FlowLayout
4) The FlowLayout manager attempts to honor the preferred size of any components
The default layout manager fror an Application is BorderLayout. An applet will use the default of FlowLayout if one is not specifically applied
Answer to Question 32)
3) Only one instance of a static variable will exist for any amount of class instances
Option 1) is more a description of a final variable. Option 2 is designed to fool Visual Basic programmers like me as this is how you can use the keyword static in VB. The modifier static can be applied to a class (only an innner class) , method or variable.
上一篇文章: 格林模拟试题三参考答案(1) 下一篇文章: 格林模拟试题三参考答案(3)

