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

 

answer 11)

3) error mine must be declared abstract
 

a class that contains an abstract method must itself be declared as abstract. it may however contain non abstract methods. any class derived from an abstract class must either define all of the abstract methods or be declared abstract itself.


answer 12)

3) one, two, default

code will continue to fall through a case statement until it encounters a break.


answer 13)

2) default, zero

although it is normally placed last the default statement does not have to be the last item as you fall through the case block. because there is no case label found matching the expression the default label is executed and the code continues to fall through until it encounters a break.


answer 14)

2,3

example 1 will not compile because if must always test a boolean. this can catch out c/c++ programmers who expect the test to be for either 0 or not 0.

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.

answer 19)

4) compilation and output of either "vandaleur", "vandaleur 0", "vandaleur 0 1" "vandaleur 0 1 2" or "vandaleur 0 1 2 3"

if that seems a vauge answer it is because you cannot be certain of the system that the underlying os uses for allocating cycles for a thread. the chances are that once the thread has been spun off in the call to start in the method piggy the main method will run to completion and the value of sname will still be vandeluer before the thread modifies it. you cannot be certain of this though.


answer 20)

3) one button occupying the entire frame saying bye

the default layout manager for a frame is a border layout. if directions are not given (ie north, south, east or west), any button will simply go in the centre and occupy all the space. an additional button will simply be placed over the previous button. what you would probably want in a real example is to set up a flow layout as in

setlayout(new flowlayout()); 


which would allow the buttons to both appear side by side, given the appropriate font and size.
applets and panels have a default flowlayout manager


 

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

责任编辑:小草

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