“null”;答案E告诉我们在程序运行期间不可能完全释放内存。
例题12:
Give the following method: 1) public void method( ){ 2) String a,b;
3) a=new String(“hello world”); 4) b=new String(“game over”); 5) System.out.println(a+b+”ok”); 6) a=null; 7) a=b;
8) System.out.println(a); 9) }
In the absence of compiler optimization, which is the earliest point the object a refered is definitely elibile to be garbage collection.
A. before line 3
B.before line 5
C. before line 6
D.before line 7
E. Before line 9 解答:D
点评:第6行将null赋值给a以后,a以前保存的引用所指向的内存空间就失去了作用,它可能被释放。所以对象a可能最早被垃圾回收是在第7行以前,故选择D选项。 例题13:
In the class java.awt.AWTEvent,which is the parent class upon which jdk1.1 awt events are based there is a method called getID which phrase accurately describes the return value of this method?
A. It is a reference to the object directly affected by the cause of the event.
B. It is an indication of the nature of the cause of the event.
C. It is an indication of the position of the mouse when it caused the event.
D. In the case of a mouse click, it is an indication of the text under the mouse at the time of the event.
E. It tells the state of certain keys on the keybord at the time of the event.
F. It is an indication of the time at which the event occurred. 解答:B
点评:请查阅JAVA类库。getID方法的返回值是“event type”。在认证考试中,总会有类似的书本以外的知识,这只能靠多实践来增长知识了。 例题14:
Which statement about listener is true?
A. Most component allow multiple listeners to be added.
B. If multiple listener be add to a single component, the event only affected one listener.
C. Component don?t allow multiple listeners to be add.
D. The listener mechanism allows you to call an addXxxxListener method as many times as is needed, specifying as many different listeners as your design require. 解答:A,D
点评:控件可以同时使用多个“addXxxxListener”方法加入多个监听器。并且当多个监听器加入到同一控件中时,事件可以响应多个监听器,响应是没有固定顺序的。 例题15:
Give the following code:
public class Example{
public static void main(String args[] ){ int l=0;
do{
System.out.println(“Doing it for l is:”+l); }while(--l>0)
System.out.println(“Finish”); } }
Which well be output:
A. Doing it for l is 3
B. Doing it for l is 1
C. Doing it for l is 2
D. Doing it for l is 0
E. Doing it for l is ?C1
F. Finish 解答:D,F
点评:本题主要考察考生对流程控制的掌握情况。这是当型循环,条件为真执行,条件为假则退出。循环体至少执行一次,故会输出D。循环体以外的语句总会被执行,故输出F。
例题16:
Give the code fragment:
1) switch(x){
2) case 1:System.out.println(“Test 1”);break; 3) case 2:
4) case 3:System.out.println(“Test 2”);break; 5) default:System.out.println(“end”); 6) }
which value of x would cause “Test 2” to the output:
A. 1
B. 2
C. 3
D. default 解答:B,C
点评:在开关语句中,标号总是不被当做语句的一部分,标号的作用就是做为条件判断而已,一旦匹配成功,就执行其后的语句,一直遭遇break语句为止。(包括default语句在内)
例题17:
Give incompleted method: 1)
2) { if(unsafe()){//do something…} 3) else if(safe()){//do the other…} 4) }
The method unsafe() well throe an IOException, which completes the method of declaration when added at line one?
A. public IOException methodName()
B. public void methodName()
C. public void methodName() throw IOException
D. public void methodName() throws IOException
E. public void methodName() throws Exception
解答:D,F
点评:IOException异常类是Exception的子类。根据多态性的定义,IOException对象也可以被认为是Exception类型。还要注意在方法声明中抛出异常应用关键字“throws”。
例题18:
Give the code fragment:
if(x>4){
System.out.println(“Test 1”);} else if (x>9){
System.out.println(“Test 2”);}
else {
System.out.println(“Test 3”);}
Which range of value x would produce of output “Test 2”?
A. x< 4
B. x>4
C. x>9
例题19:
Give the following method:
D. None 解答:D
点评:只有两种情况:大于4时输出“Test1”,小于等于4时输出“Test3”。
public void example(){
try{
unsafe();
System.out.println(“Test1”);
}catch(SafeException e){System.out.println(“Test 2”);
}finally{System.out.println(“Test 3”);} System.out.println(“Test 4”);
Which will display if method unsafe () run normally?
A. Test 1
B. Test 2
C. Test 3
D. Test 4
解答:A,C,D
点评:在正常情况下,打印Test1、Test3、Test4;在产生可捕获异常时打印Test2、Test3、Test4;在产生不可捕获异常时,打印Test3,然后终止程序。注意finally后面的语句总是被执行。
例题20:
Which method you define as the starting point of new thread in a class from which new the thread can be excution?
A. public void start()
B. public void run()
C. public void int()
D. public static void main(String args[])
E. public void runnable() 解答:B
点评:线程的执行是从方法“run( )”开始的,该方法是由系统调用的。程序员手工调用方法start(),使线程变为可运行状态。
例题21: