格林模拟试题三参考答案(2)

来源:java认证发布时间:2012-11-12 12:47:43java认证视频

 

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*

视频学习

我考网版权与免责声明

① 凡本网注明稿件来源为"原创"的所有文字、图片和音视频稿件,版权均属本网所有。任何媒体、网站或个人转载、链接转贴或以其他方式复制发表时必须注明"稿件来源:我考网",违者本网将依法追究责任;

② 本网部分稿件来源于网络,任何单位或个人认为我考网发布的内容可能涉嫌侵犯其合法权益,应该及时向我考网书面反馈,并提供身份证明、权属证明及详细侵权情况证明,我考网在收到上述法律文件后,将会尽快移除被控侵权内容。

最近更新

社区交流

考试问答