格林模拟试题三参考答案(1)Java认证考试
文章作者 100test 发表时间 2009:04:10 01:41:29
来源 100Test.Com百考试题网
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.