java模拟题

 

1.Which statement about the garbage collection mechanism are true? 
A.Garbage collection require additional program code in cases where multiple threads are running. 
B.The programmer can indicate that a reference through a local variable is no longer of interest. 
C.The programmer has a mechanism that explicit and immediately frees the memory used by Java objects. 
D.The garbage collection mechanism can free the memory used by Java Object at expectable time. 
E.The garbage collection system never reclaims memory from objects while are still accessible to running user threads. 

2. 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; 
System.out.println(a); 
9) } 
In the absence of compiler optimization, which is the earliest point the object a referred is definitely hand to be garbage collection. 
A. before line 3 B.before line 5 C. before line 6 D.before line 7 E. Before line 9 

3. 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 addXXXListener method as many times as is needed, specifying as many different listeners as your design require. 

4.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 3B. Doing it for l is 1C. Doing it for l is 2 
D. Doing it for l is 0E. Doing it for l is –1F. Finish 

5. 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. 1B. 2C. 3D. default 

6. Give incompleted method: 
1) 
2){if(unsafe()){//do something…} 
3)else if(safe()){//do the other…} 
4)} 
The method unsafe() will throw 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 

7. 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<4B. x>;4C. x>;9D. None 

8. Give the following method: 
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 1B. Test 2C. Test 3D. Test 4 
9. Which method you define as the starting point of new thread in a class from which new the thread can be execution? 
A. public void start()B. public void run()C. public void int() 
D. public static void main(String args[])E. public void runnable() 

10.Given the following class definition: 
class A{ 
protected int i; 
A(int i){ 
this.i=i; 


which of the following would be a valid inner class for this class? 
Select all valid answers: 
A. class B{ 

B.class B extends A{ 

C.class B extends A{ 
B(){System.out.println(“i=”+i);} 

D.class B{ 
class A{} 

E.class A{}

11. Which modifier should be applied to a method for the lock of object this to be obtained prior to execution any of the method body?  
A. synchronizedB. abstractC. finalD. staticE. public  

12. The following code is entire contents of a file called Example.java,causes precisely one error during compilation:  
1)class SubClass extends BaseClass{  
2) }  
3)class BaseClass(){  
4) String str;  
5) public BaseClass(){  
6) System.out.println(“ok”);}  
7) public BaseClass(String s){  
str=s;}  
9)}  
10)public class Example{  
11) public void method(){  
12) SubClass s=new SubClass(“hello”);  
13) BaseClass b=new Bas

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值