打算每天发5道题,和大家学习交流,也鞭策自己,希望大家支持。 
Q:1  
public class Test{ 
         public static void main(String args[]){ 
                   class Foo{ 
                                  public int i = 3; 
                   } 
                   Object o = (Object)new Foo(); 
                   Foo foo = (Foo)o; 
                   System.out.println("i="+foo.i); 
        } 
} 
what is the result? 
A i=3; 
B Conpilation fails; 
C A ClassCastException is thrown at line 6; 
D ---------------------------------------- at line 7; 
 
Q2  
Which two cause a compiler error?(choose two) 
A  float[] = new float(3). 
B  float f2[] = new float[]; 
C  foat[] f1 = new float[3]; 
D  float f3[] = new float[3]; 
E  float f5[] = { 1.0f;2.0f;2.0f}; 
F  float f4[] = new float float[]{ 1.0f , 2.0f, 3.0f}; 
 
Q3  
int i =1,j=10; 
do{ 
      if(i++>--j) { 
         continue; 
      } 
} 
while (i < 5); 
System.out.println("i="+i+"and j="+j); 
what is the result? 
A i=6 and j=5 
B i=5 and j=5 
C i=5 and j=6 
D i=6 and j=6 
 
Q4 
Given 
1 class Test{ 
2   private Demo d; 
3   void start(){ 
4        d = new Demo(); 
5        this.takeDemo(d); 
6   } 
7  
8   void takeDemo(Demo demo){ 
9        demo = null; 
10        demo = new Demo(); 
11   } 
12 } 
 
What id the Demo object,created on line 3,eligibe for garbage colletion? 
A After line 5; 
B After line 9; 
C After the start() method completes. 
D When the takeDemo() method completes. 
E When the instance running this code id made eligible for garbage coletion. 
 
Q6  
Which statement id true? 
A Memory is reclaimed by calling Runtime.gc(). 
B Objects are not collected if they accessible fron live threads. 
C Objects that have finalize() methods are never garbage collected. 
D Objects that have finalize() methods always have finalize() methods called before the propram ends. 
E An OutOfMemory error id only thrown if a singe block of memory connot be found that is large 
  enough for a particular requirement. 
[ 本帖最后由 fso918 于 2011-09-27  11:12 编辑 ] |