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

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

 

answers

answer to question 1)

1) float f=1/3;
2) int i=1/3;
4) double d=999d;

the fact that option 3 does not compile may be a surprise. the problem is because the default type for a number with a decimal component is a double and not a float. the additional trailing d in the option with 999 doesn't help, but it doesn't harm.


answer to question 2)

2) new

the option null (note the upper case letter) is definitely not a keyword. there is some discussion as to i. there is some discussion as to if null is a keyword but for the purpose of the exam you should probably assume it is a keyword.

the option instanceof is a bit of a misleading option that would probably not occur on the exam. the real keyword is instanceof (note that the of has no capital letter o). i had the incorrect version in an earlier version of this tutorial as it looks more likely to my eyes. the instanceof keyword looks like a method, but it is actually an operator.

the option wend is probably valid in some other language to indicate the end of a while loop, but java has no such keyword.


answer to question 3)

1) system.out.println(1+1);
2) int i=2+'2';
option 3 is not valid because single quotes are used to indicate a character constant and not a string. several people have emailed me to say that option 3 will compile. when they eventually compiled the exact code they have agreed, it will not compile. let me re-state that

string s="on"+'one';

will not compile.

option 4 will not compile because 255 is out of the range of a byte


answer to question 4)

1) the garbage collection algorithm in java is vendor implemented

threading and garbage collection are two of the few areas that are platform dependent. this is one of the
reasons why java is not suitable for realtime programming. it is not a good idea use it to control your
plane or nuclear power station. once an instance of the integer class has a value it cannot be changed.


answer to question 5)

(not on the official sub objectives but this topic does come up on the exam)

2) the randomaccessfile class allows you to move directly to any point a file.
4) the characteristics of an instance of the file class such as the directory separator, depend on the current underlying operating system

the file class can be considered to represent information about a file rather than a real file object. you can create a file in the underlying operating system by passing an instance of a file to a stream such as fileoutputstream. the file will be created when you call the close method of the stream.

上一页123下一页

视频学习

我考网版权与免责声明

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

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

最近更新

社区交流

考试问答