JAVA认证格林模拟试题三答案及解析
来源:优易学  2009-11-28 15:49:08   【优易学:中国教育考试门户网】   资料下载   IT书店
文章页内部300*250广告位

 

answer to question 55)

1) compile time error

this might be considered a "gocha" or deliberate attempt to mislead you because i has been given the data type of long and the parameter must be of long and the parameter must be either a byte, char, short or int. if you attempt to compile this code with jdk 1.2 you will get an error that says something like "incompatible type for switch, explicit cast needed to convert long to int". answering with option 2 would have been reasonable because if the parameter had been an integer type the lack of break statements would have caused this output. if you gave either of the answers you should probably revise the subject.


answer to question 56)

1) system.out.println(i++);
3) system.out.println(i);
4) system.out.println(i==);

the options for this question might look suspiciously easy if you are not aware of the effects of the post-increment operators. the ++ and == operations for examples 1 and 4 only come into effect after the output operations, ie after whatever else is done to them on that line of code. option 2 should be fairly obvious as you should know that the single quote characters indicate a char value, ie storing the character rather than the numberical value for 0.


answer to question 57)

4) system.out.println( ((agg) a).getfields());

the base type reference to the instance of the class agg needs to be cast from base to agg to get access to its methods.the method invoked depends on the object itself, not on the declared type. so, a.getfield() tries to invoke a getfield method in base which does not exist. but the call to ((agg)a).getfield() will invoke the getfield() in the agg class. you will be unlucky to get a question as complex as this on the exam. if you think option 1 is valid, have a go at compiling the code.


answer to question 58)

2) compilation and output of false

a variable defined at class level will always be given a default value and the default value for the primitive type boolean is false


answer to question 59)

1) the x,y coordinates of an instance of mouseevent can be obtained using the getx() and gety() methods
4) the time of a mouseevent can be extracted using the getwhen method

if you chose option 4, referring to the mythical gettime method you have made a reasonable guess based on the normal conventions of java. however the conventions do not always hold true. if you chose option 3 perhaps you are not as aware of the conventions as you should be.


answer to question 60)

2) the program will run and output only "fliton"

this question tests your knowledge of the principle that the finally clause will almost always run.

 

上一页  [1] [2] [3] [4] [5] 

责任编辑:小草

收藏此页】【 】【打印】【回到顶部
计算机文章页底部500*200广告
文章搜索:
 相关文章
计算机底部580*90广告
文章页右侧第一330*280广告
计算机文章页资讯推荐
热点资讯
文章页330尺寸谷歌广告位
资讯快报
热门课程培训