格林模拟试题三参考答案(2)
answer to question 16)
2) compile time error
an error occurs when the class severn attempts to call the zero parameter constructor in the class base because the base class has an integer constructor java does not provide the "behind the scenes" zero parameter constructor.
for more information on this topic go to
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.PqfGFk?3\OE*?h B[本资料来源于贵州学习网 http://www.gzu521.com]PqfGFk?3\OE*?h B
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.