格林模拟试题一参考答案

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

 

answer 15)

3) no such file found, doing finally, -1

the no such file found message is to be expected, however you can get caught out if you are not aware that the finally clause is almost always executed, even if there is a return statement.


answer 16)

1) methods cannot be overriden to be more private

static methods cannot be overriden but they can be overloaded. if you have doubts about that statement, please follow and read carefully the link given to the sun tutorial below. there is no logic or reason why private methods should not be overloaded. option 4 is a jumbled up version of the limitations of exceptions for overriden methods


answer 17)

3) runtime exception

without the cast to sub you would get a compile time error. the cast tells the compiler that you really mean to do this and the actual type of b does not get resolved until runtime. casting down the object hierarchy is a problem, as the compiler cannot be sure what has been implemented in descendent classes. casting up is not a problem because sub classes will have the features of the base classes. this can feel counter intuitive if you are aware that with primitives casting is allowed for widening operations (ie byte to int).


answer 18)

1) system.out.println( -1 >>> 2);will output a result larger than 10
2) system.out.println( -1 >>> 2); will output a positive number
3) system.out.println( 2 >> 1); will output the number 1

you can test this with the following classm

public class shift{
static int i=2;
public static void main(string argv[]){
system.out.println( -1 >>> 2);
system.out.println( -1 >>> 2);
system.out.println( 2 >> 1);
}

}

java does not have a <<< operator. the operation 1 << 2 would output 4

because of the way twos complement number representation works the unsigned right shift operation means a small shift in a negative number can return a very large value so the output of option 1 will be much larger than 10.

the unsigned right shift places no significance on the leading bit that indicates the sign. for this shift the value 1 of the bit sign is replaced with a zero turning the result into a positive number for option 2.

视频学习

我考网版权与免责声明

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

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

最近更新

社区交流

考试问答