SCJP认证复习——经典题库

 
我把 147 104 的题综合了一下,从个人的观点做了一些解析。也把其中的一些错误纠正了一些,多数题都通过了上机实测。但个人能力有限,对答案的正确性仍然不敢保证全都正确,所以请各位自行处理。
 
 
1.
Given:
1. public class returnIt {
2. returnType methodA(byte x, double y){
3. return (short) x/y * 2;
4.      }
5. }
 
What is the valid returnType for methodA in line 2?
A.     int
B.     byte
C.     long
D.     short
E.     float
F.     double
 
 
Answer F
注释 :short 类型的 x ,除以 double 类型的 y ,再乘 int 2 ,所以结果是 double 类型的。注意第三行的强制转换,只是转换了 x
2.
1) class Super{
2) public float getNum(){return 3.0f;}
3) }
4)
5) public class Sub extends Super{
6)
7) }
which method, placed at line 6, will cause a compiler error?
A. public float getNum(){return 4.0f;}
B. public void getNum(){}
C. public void getNum(double d){}
D. public double getNum(float d){return 4.0d;}
 
Answer :B
注意这道题主要考的是方法的 overload override 。对于 overload ,只有参数列表不同,才做为标准,而返回值和访问控制关键字不能做为标准,所以 B 错在方法名相同,但只有返回值不同,这是错的。 C D 是正确的 overload 。对于 override ,则访问控制关键字只能更加公有化,异常只能是超类方法抛出的异常的子类,也可以不抛出。返回类型,参数列表必须精确匹配。所以 A 是正确的 override
 
3.
1)public class Foo{
2)     public static void main(String args[]){
3)     try{return;}
4)     finally{ System.out.println("Finally");}
5)     }
6)     }
what is the result?
A. The program runs and prints nothing.
B. The program runs and prints “Finally”.
C. The code compiles, but an exception is thrown at runtime.
D. The code will not compile because the catch block is missing.
 
Answer:b
try......catch......finally 的问题。程序中如果遇到 return ,则 finally 块先被执行,然后再执行 retrun ,而 finally 块后面的语句将不被执行。如果遇到 System.exit(1) ,则 finally 块及其后的语句都不执行,整个程序退出,还执行什么呀。
 
4.
1) public class Test{
2) public static String output="";
3) public static void foo(int i){
4)   try {
5)        if(i==1){
6)                    throw new Exception();
7)               }
8)         output +="1";
9)       }
10)     catch(Exception e){
11)                     output+="2";
12)                     return;
13)                      }
14)     finally{
15)                output+="3";
16)           }
17)      output+="4";
18) }
19) public static void main(String args[]){
20)              foo(0);
21)              foo(1);
22)    
23)   }
24) }
what is the value of output at line 22?
 
 
Asnwer:13423
执行第一个 foo(0) 时,执行第 8 条语句, output=1 ,然后执行语句 15 output=13 ,然后是 17 条, output=134 ,因为是 static 类型的变量,所以任何对其值的修改都有效。执行第二条 foo(1), 先执行语句 5 ,结果抛出异常,转到 catch 块, output=1342 finally 任何情况下都执行,所以 output=13423 ,然后 return 跳出方法体,所以 output=13423
5
1)public class IfElse{
2)public static void main(String args[]){
3)if(odd(5))
4)System.out.println("odd");
5)else
6)System.out.println("even");
7)}
8)public static int odd(int x){return x%2;}   
9)}
what is output?
 
Answer: 编译错误。
if 中的判断条件的结果必须是 boolean 类型的。注意这里说的是结果 .
 
6 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
1)class ExceptionTest{
2)public static void main(String args[]){
3)try{
4)methodA();
5)}catch(IOException e){
6)System.out.println("caught IOException");
7)}catch(Exception e){
8)System.out.println("caught Exception");
9) }
10) }
11)}
If methodA() throws a IOException, what is the result?
 
Answer: caught IOException
如果 methodA() 抛出 IOExecption ,被语句 6 捕获,输出 caught IOException ,然后呢??然后就结束了呗。
7
1)int i=1,j=10;
2)do{
3)          if(i++>--j) continue;
4)}while(i<5);
After Execution, what are the value for i and j?
A. i=6 j=5
B. i=5 j=5
C. i=6 j=4
D. i=5 j=6
E. i=6 j=6
 
Answer: d
程序一直循环,直到 i=4 j=6 时,执行完语句 3 后, i ++ ,这时 i 就等于了 5 continue 后就不能再循环了,所以选 D
8
1)public class X{
2)          public Object m(){
3)                        Object o=new Float(3.14F);
4)                        Object[] oa=new Object[1];
5)                        oa[0]=o;
6)                        o=null;
7)                        oa[0]=null;
8)                        System.out.println(oa[0]);
9)                                   }
10)                             }
which line is the earliest point the object a refered is definitely elibile to be garbage collectioned?
A.After line 4   
B. After line 5 
C.After line 6   
D.After line 7   
E.After line 9(that is,as the method returns)
 
Answer: d
当执行第 6 行后,仍然有对象指向 o ,所以 o 不能满足条件,当第 7 条语句被执行后,就再也没有对象指向 o 了,所以选 D
9 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@   
   1) interface Foo{
   2)          int k=0;
   3)    }
   4) public class Test implements Foo{
   5)             public static void main(String args[]){
   6)                        int i;
   7)                          Test test =new Test();
   8)                           i=test.k;
   9)                           i=Test.k;
 10)                           i=Foo.k;
 11)                            }
 12) }
 
What is the result?
A. Compilation succeeds.
B. An error at line 2 causes compilation to fail.
C. An error at line 9 causes compilation to fail.
D. An error at line 10 causes compilation to fail.
E. An error at line 11 causes compilation to fail.
 
Answer: A
编译通过,通过测试的
10
what is reserved(保留) words in java?
A. run
B. default
C. implement
D. import
 
 
Answer: b D
11
1)public class Test{
2) public static void main(String[] args){
3) String foo=args[1];
4) Sring bar=args[2];
5) String baz=args[3];
6) }
7) }
 java Test Red Green Blue
what is the value of baz?
A. baz has value of ""
B. baz has value of null
C. baz has value of "Red"
D. baz has value of "Blue"
E. baz has value of "Green"
F. the code does not compile
G. the program throw an exception
 
 
 
Answer: G
当执行java Test Red Green Blue 时,数组 args 只有 [0][1][2] ,运行时ArrayIndexOutOfBoundsException 这个异常会被抛出,数组越界。
12
int index=1;
int foo[]=new int[3];
int bar=foo[index];
int baz=bar+index;
what is the result?
A. baz has a value of 0
B. baz has value of 1
C. baz has value of 2
D. an exception is thrown
E. the code will not compile
 
Answer: b
数组初始化后默认值是 0 ,所以 baz=0+1=1
13
which three are valid declaraction(行为) of a float?
 A. float foo= -1;
 B. float foo=1.0;
 C. float foo=42e1;
 D. float foo=2.02f;
 E. float foo=3.03d;
 F. float foo=0x0123;
 
Answer: A D F
其它的系统都会认为是 double 类型,所以出错。说一下 A C 的区别吧, -1 系统会认为是一个 int 类型,把 int 类型再赋给 float 类型的 foo ,当然没错了,可 C 就不同啦, 42e1 int 类型吗??
14
1)public class Foo{
2) public static void main(String args[]){
3) String s;
4) System.out.println("s="+s);
5) }
6) }
 what is the result?
A. The code compiles and “s=” is printed.
B. The code compiles and “s=null” is printed.
C. The code does not compile because string s is not initialized(初始化).
D. The code does not compile because string s cannot be referenced(引用).
E. The code compiles, but a NullPointerException is thrown when toString is called.
 
Answer:C
只有实例变量系统才给予自动赋默认值的这种待遇
 
15  
 1) public class Test{
 2) public static void main(String args[]){
 3) int i=oxFFFFFFF1;
 4) int j=~i;
 5)
 6) }
 7) }
which is decimal value of j at line 5?
A. 0      
B.1    
C.14    
D.-15    
E. compile error at line 3     
F. compile error at line 4
 
Answer: C
算一算就知道了。
 
16
float f=4.2F;
Float g=new Float(4.2F);
Double d=new Double(4.2);
Which are true?
A. f==g   
B. g==g   
C. d==f   
D. d.equals(f) 
E d.equals(g) 
F. g.equals(4.2);
 
Answer: B
== 两边类型不同不相等。所以 A C 不等。 equals 只能用于引用类型,不能用于基本类型,所以 D 不对,而且两边类型不兼容的话 , 即使对象的内容一样 , 也不相等,所以 E F 不对。
17 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 
1)public class Test{
2) public static void add3(Integer i){
3)        int val=i.intValue();
4)        val+=3;
5)        i=new Integer(val);
6) }
7) public static void main(String args[]){
8)       Integer i=new Integer(0);
9)       add3(i);
10)       System.out.println(i.intValue());
11) }
12)}
 what is the result?
 A. compile fail       
 B.print out "0"      
 C.print out "3"   
 D.compile succeded but exception at line 3
 
Answer: b
在第五行里,程序又操作了 New ,重新分配了内存空间。所以此 i 非彼 i 啦。
18
1)public class Test{
2) public static void main(String[] args){
3)    System.out.println(6^3); //‘^’为XOR
4)    }
5)      }
 what is output?
 
Answer: 5 算呗。
19
1) public class Test{
2) public static void stringReplace(String text){
3)    text=text.replace('j','l');
4) }
5) public static void bufferReplace(StringBuffer text){
6)     text=text.append("c");
7)    }
8) public static void main(String args[]){   
9)    String textString=new String("java");
10)    StringBuffer textBuffer=new StringBuffer("java");
11)     StringReplace(textString);
12)     bufferReplace(textBuffer);
13) System.out.println(textString+textBuffer);
14)     }
15)     }
 what is the output?
 
Answer: javajavac
textString String 类型的,具有不变性,语句 3 其实是创建了一个新的字符串,而不是修改原来的 textString ,而对于 StringBuffer 类型的对象,则所有修改都是实在的。所以在语句 6 textBuffer 变成了 javac ,所以输出为 javajavac
 
20
1)public class ConstOver{
2) public ConstOver(int x, int y, int z){}
3) }
 which two overload the ConstOver constructor?
 A.ConstOver(){}
 B.protected int ConstOver(){}
 C.private ConstOver(int z, int y, byte x){}
 D.public void ConstOver(byte x, byte y, byte z){}
 E.public Object ConstOver(int x, int y, int z){}
 
Answer: a,c
主要的问题是 overload ,参数列表必须不同,方法名相同,访问控制无限制。也无异常限制。这道题因为是构造器,所以 B D E 不对,因为构造器不能有返回类型。
21
1)public class MethodOver{
2) public void setVar(int a, int b, float c){}
3) }
 which overload the setVar?
 A.private void setVar(int a, float c, int b){}
 B.protected void setVar(int a, int b, float c){}
 C.public int setVar(int a, float c, int b){return a;}
 D.public int setVar(int a, float c){return a;}
 
Answer: a,c,d
overload 无访问控制限制,所以 A 对,顺序也属于参数列表,顺序不同也一样是 overload ,所以 C 正确, D 当然正确了,参数列表明显不同。
22 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
1)class EnclosingOne{
2)public class InsideOne{}
3) }
4)public class InnerTest{
5) public static void main(String args[]){
6) EnclosingOne eo=new EnclosingOne();
7) //insert code here
8) }
9)}
A.InsideOne ei=eo.new InsideOne();
B.eo.InsideOne ei=eo.new InsideOne();
C.InsideOne ei=EnclosingOne.new InsideOne();
D.InsideOne ei=eo.new InsideOne();
E.EnclosingOne.InsideOne ei=eo.new InsideOne();
 
Answer: e
这里边的一些形式是固定的。
1 )静态方法访问非静态内类:
                     方法为:
       Outer myouter=new Outer(); //这里的 myouter 是创建的外部类的对象。
       Outer.Inner myinner=myouter.new Inner(); // myinner 是内类的对象。
       然后再 myinner.showName(); // showName() 是外类中的非静态方法。
2 )非静态方法访问非静态内类
                     直接创建该内部类的对象: new Inner().showName();
3 )静态方法访问静态内类:
                     也是直接创建该内部类的对象,即 Inner myinner = new Inner() ,或者 Outer.Inner myinner = new Outer.Inner() 也行得通哦。
23
What is "is a" relation?
A.public interface Color{}
 public class Shape{private Color color;}
B.interface Component{}
 class Container implements Component{
   private Component[] children;
    }
C.public class Species{}
   public class Animal{private Species species;}  
 
Answer: b
"is a " 意思为是什么:定义了一个超类和一个子类之间的一种直接关系 : 子类是超类的一种。也即是继承的关系
24 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
1)package foo;
2)
3)public class Outer{
4)public static class Inner{
5)}
6)}
which is true to instantiated(事例) Inner class inside Outer?
A. new Outer.Inner()
B. new Inner()
 
Answer: a,b
25
class BaseClass{
 private float x=1.0f;
 private float getVar(){return x;}
   }
class SubClass extends BaseClass{
 private float x=2.0f;
 //insert code
 }
what are true to override getVar()?
A.float getVar(){
B.public float getVar(){
C.public double getVar(){
D.protected float getVar(){
E.public float getVar(float f){
 
Answer: a,b,d
又是 override 的问题,参数列表和返回值以及方法名 ( 好像是费话 ) 必须精确匹配 , 访问控制要更公有化 , 如果抛出异常 , 那么必须异常本身或其子集或什么都不抛 .
26
public class SychTest{
 private int x;
 private int y;
 public void setX(int i){ x=i;}
 public void setY(int i){y=i;}
 public Synchronized void setXY(int i){
   setX(i);
   setY(i);
 }
 public Synchronized boolean check(){
      return x!=y;  
   }
   }
 Under which conditions will check() return true when called from a different class?
 A.check() can never return true.
 B.check() can return true when setXY is callled by multiple threads.
 C.check() can return true when multiple threads call setX and setY separately.
 D.check() can only return true if SychTest is changed allow x and y to be set separately.
 
Answer: c
27
Given:
1.     public class SyncTest (
2.     private int x;
3.     private int y;
4.     private synchronized void setX (int i) (x=1;)
5.     private synchronized void setY (int i) (y=1;)
6.     public void setXY(int 1)(set X(i); setY(i);)
7.     public synchronized Boolean check() (return x !=y;)
8.     )
 
Under which conditions will check () return true when called from a different class? 
A.     Check() can never return true
B.     Check() can return true when setXY is called by multiple threads
C.     Check() can return true when multiple threads call setX and setY separately.
D.     Check() can only return true if SyncTest is changed to allow x and y to be set separately.
 
Answer:B 
28
Given:
1.     public class SyncTest {
2.     private int x;
3.     private int y;
4.     public synchronized void setX (int i) (x=1;)
5.     public synchronized void setY (int i) (y=1;)
6.     public synchronized void setXY(int 1)(set X(i); setY(i);)
7.     public synchronized Boolean check() (return x !=y;)
8.     )
Under which conditions will check () return true when called from a different class?
A. Check() can never return true.
B. Check() can return true when setXY is called by multiple threads.
C. Check() can return true when multiple threads call setX and setY separately.
D. Check() can only return true if SyncTest is changed to allow x and y to be set separately.
 
Answer: A
哪一个不加锁,就从哪一个入手,但这道题全都加锁了,所以先 A
29
1)public class X implements Runnable{
2)private int x;
3)private int y;
4)public static void main(String[] args){
5)    X that =new X();
6) (new Thread(that)).start();
7) (new Thread(that)).start();
  }
9) public synchronized void run(){
10) for(;;){
11)       x++;
12)       y++;
13) System.out.println("x="+x+",y="+y);
14)     }
15)    }
16) }   
 what is the result?
A.An error at line 11 causes compilation to fail.
B.Errors at lines 6 and 7cause compilation to fail.
C.The program prints pairs of values for x and y that might not always be the same on the same    line (for example, “x=2, y=1”)
D.The program prints pairs of values for x and y that are always the same on the same line (for example, “x=1, y=1”. In addition, each value appears twice (for example, “x=1, y=1” followed by “x=1, y=1”)
E.The program prints pairs of values for x and y that are always the same on the same line (for example, “x=1, y=1”. In addition, each value appears twice (for example, “x=1, y=1” followed by “x=2, y=2”)
 
Answer: E
这道题有问题,当两个线程同名时,输出 x=1,y=1 ……,但只一次,而当两个线程不同名时,输出就是两次。理论上加锁时,线程 1 会执行直到结束,然后线程 2 才会开始执行。
30
Click the exhibit button:
1.     public class X implements Runnable(
2.     private int x;
3.     private int y;
4.    
5.     public static void main(String[]args)
6.     X that = new X();
7.     (new Thread(that)).start();
8.     (new Thread(that)).start();
9.     )
10. 
11. public void run() (
12. for (;;) (
13. x++;
14. y++;
15. System.out.printIn(“x=” + x + “, y = ” + y);
16. )
17. )
18. )   
 
What is the result?
A.     Errors at lines 7 and 8 cause compilation to fail.
B.     The program prints pairs of values for x and y that might not always be the same on the same line (for example, “x=2, y=1”).
C.     The program prints pairs of values for x and y that are always the same on the same line (for example, “x=1, y=1”. In addition, each value appears twice (for example, “x=1, y=1” followed by “x=1, y=1”).
D.     The program prints pairs of values for x and y that are always the same on the same line (for example, “x=1, y=1”.) In addition, each value appears only for once (for example, “x=1, y=1” followed by “x=2, y=2”).
 
Answer D
这道题也有问题,当两个线程同名的情况下,只输出一次,但当两个线程不同名的情况下,可以清楚的看到两个线程是交替执行的, x=1,y=1 后现可以是任何东西,也可能是另一个线程的 x=1,y=1
31
class A implements Runnable{
int i;
public void run(){
 try{
     Thread.sleep(5000);
      i=10;
     }catch(InterruptException e){}
     }
     }
 public static void main(String[] args){
    try{
       A a=new A();
       Thread t=new Thread(a);
       t.start();
17)
    int j=a.i;
19)
    }catch(Exception e){}
    }
    }
what be added at line line 17,ensure j=10 at line 19?
A. a.wait();   
B. t.wait();   
C. t.join();   
D.t.yield();   
E.t.notify(); 
F.     a.notify();
G.t.interrupt();
 
Answer: c
32 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Given an ActionEvent, which method allows you to identify the affected component?
A. public class getClass()
B. public Object getSource()
C. public Component getSource()
D. public Component getTarget()
E. public Component getComponent()
F. public Component getTargetComponent()
 
Answer: c
33 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
import java.awt.*;
public class X extends Frame{
 public static void main(String[] args){
 X x=new X();
 x.pack();
 x.setVisible(true);}
 public X(){
   setLayout(new GridLayout(2,2));
   Panel p1=new Panel();
 add(p1);
Button b1=new Button("One");
p1.add(b1);
Panel p2=new Panel();
add(p2);
Button b2=new Button("Two");
 p2.add(b2);
Button b3=new Button("Three");
 p2.add(b3);
Button b4=new Button("Four");
 add(b4);
 }
 }
when the frame is resized,
A.all change height    
B.all change width   
C.Button "One" change height
D.Button "Two" change height 
E.Button "Three" change width
F.Button "Four" change height and width
 
Answer: f
34
1)public class X{
2)     public static void main(String[] args){
3)      String foo="ABCDE";
4)      foo.substring(3);
5)      foo.concat("XYZ");
6)     }
7)    }
what is the value of foo at line 6?
 
Answer: ABCDE
问题的关键在于 String 的不变性,虽然又是 substring 又是 concat 的,但都只是创建了一个新的字符串,原本的 foo 一直都没有被改变,也不可能被改变。
35 Which method is an appropriate way to determine the cosine of 42 degrees?
A. double d = Math.cos(42);
B. double d = Math.cosine(42);
C. double d = Math.cos(Math.toRadians(42));
D. double d = Math.cos(Math.toDegrees(42));
E. double d = Math.cosine(Math.toRadians(42));
 
Answer: c
toRadians 是把一个角度转换成一个弧度, cos 方法的参数必须是以弧度表示的。
36 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
public class Test{
 public static void main(String[] args){
 StringBuffer a=new StringBuffer("A");
 StringBuffer b=new StringBuffer("B");
 operate(a,b);
 System.out.println(a+","+b);
 }
 public static void operate(StringBuffer x, StringBuffer y){
 x.append(y);
 y=x;
 }
 }
 what is the output?
 
Answer: AB,B 有些不理解。我只能认为 y=x 这名语句没有改变 b
37 Given:
13. public class Foo {
14.    public static void main (String [] args) {
15.       StringBuffer a = new StringBuffer (“A”);
16.       StringBuffer b = new StringBuffer (“B”);
17.      operate (a,b);
18.      system.out.printIn{a + “,” +b};
19. )
20. static void operate (StringBuffer x, StringBuffer y) {
21.            y.append (x);
22.            y = x;
23.      )
24. }
 
What is the result?
A.The code compiles and prints “A,B”.
B.The code compiles and prints “A, BA”.
C.The code compiles and prints “AB, B”.
D.The code compiles and prints “AB, AB”.
E.The code compiles and prints “BA, BA”.
F.The code does not compile because “+” cannot be overloaded for stringBuffer.
 
Answer B  
38.
1) public class Test{
 2) public static void main(String[] args){
 3) class Foo{
 4)       public int i=3;
5)              }
 6)               Object o=(Object)new Foo();
 7)               Foo foo=(Foo)O;
 8)                      System.out.println(foo.i);
 9) }
 10) }
what is result?
A.compile error at line 6
B.compile error at line 7
C.print out 3
 
Answer: C
简单的说,要访问变量的时候,看等号左边,访问方法的时候看等号右边,但对于 static 类型的方法除外。
39
public class FooBar{
            public static void main(String[] args){
                           int i=0,j=5;
4) tp: for(;;i++){
                                              for(;;--j)
                                                    if(i>j)break tp;
                                             }
                     System.out.println("i="+i+",j="+j);
 }
 }
what is the result?
A.i=1,j=-1     B. i=0,j=-1 C.i=1,j=4    D.i=0,j=4  
E.compile error at line 4
 
Answer: b break tp; 退出了最外层的 for 循环,程序接着从 System 开始执行。
40
Given:
1.     public class ForBar {
2. public static void main(String []args)    {
3.     int i = 0, j = 5;
4.     tp: for (;;) {
5.     i ++;
6.     for(;;)
7.     if(i > --j) break tp;
8.     }
9.     system.out.printIn(“i = ” + i + “, j = “+ j);
10. }
11. }
 
What is the result?
A.The program runs and prints “i=1, j=0”
B.The program runs and prints “i=1, j=4”
C.The program runs and prints “i=3, j=4”
D.The program runs and prints “i=3, j=0”
E.An error at line 4 causes compilation to fail
F.An error at line 7 causes compilation to fail
 
Answer A
在第五行 i 就变成了 1 ,第七行里 j 就一直往下减吧,然后退出最外层的 for
 
41
 public class Foo{
   public static void main(String[] args){
   try{System.exit(0);}
   finally{System.out.println("Finally");}
 }
 }
 what is the result?
 A.print out nothing
 B.print out "Finally"
 
Answer: A
System.exit(0) 可以强行终止 JVM ,可见优先级最高啦,有了它, finally 就玩完了。 Systtem.exit() 中不只可以放 0 ,可以是任何整数和字符。
42
which four types of objects can be thrown use "throws"?
A.Error
B.Event
C.Object
D.Excption
E.Throwable
F.RuntimeException
 
Answer: A,D,E F
throws 可以抛出各种异常,但 Event Object 算哪门子的异常呀?
43
1)public class Test{
2) public static void main(String[] args){
3) unsigned byte b=0;
4) b--;
5)
6) }
7) }
what is the value of b at line 5?
A.-1    B.255 C.127 D.compile fail E.compile succeeded but run error
 
Answer: d unsigened byte ???? java 里怎么可以这样子定义变量哩???
44
public class ExceptionTest{
      class TestException extends Exception{}
     public void runTest() throws TestException{}
     public void test() /* point x */ {
       runTest();
     }
 }
 At point x, which code can be add on to make the code compile?
A.throws Exception
B.catch (Exception e)
C.throws RuntimeException
D.catch (TestException e)
E.no code is necessary
 
Answer: A 
有些没看明白,我觉得没有 try 就不能有 catch ,所以 B,D 错,而 C 里边的 RuntimeException Exception 没关系,所以错,就只有 A 啦。
45
String foo="blue";
boolean[] bar=new boolean[1];
 if(bar[0]){
    foo="green";
 }
what is the value of foo?
 A."" B.null C.blue    D.green
 
Answer: C
bar 这个数组的默认值是 flase ,所以 if 不改变 foo 。不过我认为就算是改变了 foo foo 也还是 blue.
46.
 public class X{
 public static void main(String args[]){
 Object o1=new Object();
 Object o2=o1;
 if(o1.equals(o2)){
   System.out.prinln("Equal");
    }
    }
    }
 what is result?
 
Answer: Equal
equals() 用于检测对象的值,即检测对象所引用的内部数据的值。只能用于引用类型。 String 类, String 对象在代表相同字符串时相等。 equals() 返回真。 Boolean 对象在值相同时相等。 equals() 返回真。但如果比较的两个对象的类型不相同,哪怕是值相同,也返回假。
这道题两个对象类型相同,而且值也相同,摆明了返回真嘛。
47
which two are equivalent?
A. 3/2
B. 3<2
C. 3*4
D. 3<<2
E. 3*2^2
F. 3<<<2
 
 
A=1,
B=False,
C=12,
D=12,
E=3 2 再异或 2=4,
F= ????
 Answer: c,d
 
 
 
48
int index=1;
String[] test=new String[3];
String foo=test[index];
what is the result of foo?
 
A. foo has the value “”
B. foo has the value null
C. an exception is thrown
D. the code will not compile
 
 
Answer: b
String 的数组默认是 null, 还要注意, null 和空字符是两个东东。
49 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
public class Test{
 static void leftshift(int i, int j){
    i<<=j;
   }
 public static void main(String args[]){
    int i=4, j=2;
   leftshift(i,j);
 System.out.println(i);
   }
   }
 what is the result?
A.2
B.4
C.8
D.16
E.The code will not compile
 
Answer: B
传递的是简单类型呀!!也就是说传递的是值的拷贝,所以原本的值是不变的!
50 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
public class X{
 private static int a;
 public static void main(String[] args){
   modify(a);
   System.out.println(a);
   }
 public static void modify( int a){
    a++;
   }
   }
 what is the result?
 
Answer: 0
和上一题不一样。这里的 a 是类变量,也就是说所有实例以及方法都共用这么一个宝贝东东,所以其中的一个实例方法对它做了修改,那相对于其它的实例方法也就都已经个改了。所以应该是 a++, 也就是 1 ,但为什么是 0 呢?原因就在于 modify 中定义的局部变量也叫 a, 在方法中修改的变量是局部变量 a 啦,别大意了呀。哈哈。这道题和下一道题我看了足有十分钟,才分清所以然来。当然,像我这么笨的人没几个啦 ~~~~~~~~~~~~
51
1. public class Test {
 2.    private static int j=0;
 3.
 4.    public static boolean methodB(int k) {
 5.      j+=k
 6.      return true; 
 7.    }
 8.
 9.  public static void methodA(int I) {
 10.      boolean b;
 11.      b=i>10&methodB(1);
 12.      b=i>10&&methodB(2);
 13.    }
 14.
 15.    public static void main(String args[]) {
 16.      methodA(0);
 17.
 18.    }
 19.}
What is the value of j at line 17?
 A. 0     
 B. 1
 C. 2
 D. 3
 E. The code will not compile.
 
   Answer : B
看上题解释的前半部
52
class A{
 public String toString(){         
 return "4";
 }
 }
class B extends A{
 public String toString(){
    return super.toString()+"3";
   }
   }
 public class Test{
    public static void main(String[] args){
     B b=new B();
 System.out.println(b.toString());
 }
 }
 what is the result?
 
Answer: 43 对象 b B 类的实例,理所应当调用 B 类的方法, B 类方法再调用超类 A 中的方法。
53
 class A implements Runnable{
 public int i=1;
 public void run(){
 this.i=10;
 }
 }
 public class Test{
 public static void main(String[] args){
   A a=new A();
 11) new Thread(a).start();
      int j=a.i;
 13)
 }
 }
 what is the value of j at line 13?
 A. 1
 B. 10
 C. the value of j cannot be determined
 D. An error at line 11 cause compilation to fail
 
Answer: c
在11 行线程开始时(runnable 状态),什么时候运行(running 状态)是不确定的,所以说j 的值是不能确定的。
54
public class SyncTest{
     public static void main(String[] args){
        final StringBuffer s1=new StirngBuffer();
        final StringBuffer s2=new StirngBuffer();              
        new Thread(){
           public void run(){
              Synchronized(s1){
                 s1.append("A");
                 Synchronized(s2){
                    s2.append("B");
                    System.out.print(s1);
                    System.out.print(s2);
                 }
              }
           }
       }.start();
       new Thread(){
          public void run(){
             Synchronized(s2){
                s2.append("C");
                Synchronized(s1){
                   s1.append("D");
                   System.out.print(s2);
                   System.out.print(s1);
                }
            }
         }
       }.start();          
    }
 }
 what is the result?
 A.the result depends on different system and different thread model
 B.the result cannot be determined
 
Answer: A,B
不同的计算机,对线程的执行情况也就不同,所以这道题道底会输出成什么样是不可确定的,看具体的机器情况而定。
55
 public class Test{
 public static void main(String[] args){
 String foo="blue";
 4)String bar=foo;
 5)foo="green";
 6)System.out.println(bar);
 }
 }
 what is the result?
A.An exception is thrown.
B.The code will not compile.
C.The program prints “null”.
D.The program prints “blue”.
E.The program prints “green”.
 
Answer: D
这道题不用多说什么了吧,其实 String 的不变性使得 4 5 6 行都创建了一个新的字符串。
 
56
which interface Hashtable implements?
A. java.util.Map
B. java.util.List
C. java.util.Hashable
D. java.util.Collection
 
Answer: a
57 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
which two are true?
A. static inner class requires a static initializer
B. A static inner class requires an instance of the enclosing class
C. A static inner class has no reference to an instance of the enclosing class
D. A static inner class has accesss to the non-static member of the other class
E. static members of a static inner class can be referenced using the class name of the static inner class
 
Answer: c,e
 
58 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
which two are true?
A. An anonymous inner class can be declared inside of a method
B. An anonymous inner class constructor can take arguments in some situations
C. An anonymous inner class that is a direct subclass of Object can implements multiple interface
D. Even if a class Super does not implement any interfaces, it is still possible to define an anonymous inner class that is an immediate subclass of Super that implements a single interface
E. Even if a class Super does not implement any interfaces, it is still possible to define an anonymous inner class that is an immediate subclass of Super that implements multipe interface
 
Answer: a,d
59
class A{
     public int getNumber(int a){
       return a+1;
 }
}
   class B extends A{
public int getNumber(int a, char c){
     return a+2;
    }
    public static void main(String[] args){
    B b=new B();
14) System.out.println(b.getNumber(0));
    }
    }      
 what is the result?
A. compilation succeeds and 1 is printed
B. compilation succeeds and 2 is printed
C. An error at line 8 cause compilation to fail
D. An error at line 14 cause compilation to fail
 
Answer: a
当子类没有合适的方法时,调用超类中的方法。
 
 
60
Click the exhibit button:
1. class A {
2. public int getNumber(int a) {
3.      return a + 1;
4. }
5. }
6.   
7. class B extends A {
8. public int getNumber (int a) {
9. return a + 2
10. }
11.   
12. public static void main (String args[]) {
13. A a = new B();
14. System.out.printIn(a.getNumber(0));
15.     }
16. }   
 
What is the result?
A.     Compilation succeeds and 1 is printed.
B.     Compilation succeeds and 2 is printed.
C.     An error at line 8 causes compilation to fail.
D.     An error at line 13 causes compilation to fail.
E.     An error at line 14 causes compilation to fail.
 
Answer:b
61 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
 import java.awt.*;
 public class X extends Frame{
 public static void main(String[] args){
   X x=new X();
   x.pack();
   x.setVisible(true);
   }
 public X(){
 setLayout(new BorderLayout());
 Panel p=new Panel();
 add(p,BorderLayout.NORTH);
 Button b=new Button("North");
 p.add(b);
 Button b1=new Button("South");
 add(b1,BorderLayout.SOUTH);
 }
   which two are true?
 A. The button labeled "North" and "South" will have the same width
 B. The button labeled "North" and "South" will have the same height
 C. The height of the button labeled "North" can vary if the Frame is resized
 D. The height of the button labeled "South" can vary if the Frame is resized
 E. The width of the button labeled "North" is constant even if the Frame is resized
 F. The width of the button labeled "South" is constant even if the Frame is resized
 
Answer: B,F
62 which two interfaces provide the capability to store objects using a key-value pair?
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
A. java.util.Map
B. java.util.Set
C. java.util.List
D. java.util.SortedSet
E. java.util.SortedMap
F. java.util.Collection
 
Answer: a,e
63 which two declaretions prevent the overriding of a method?
A. final void methoda(){}
B. void final methoda(){}
C. static void methoda(){}
D. static final void methoda(){}
E. final abstract void methoda(){}
 
Answer: ad
A D 正确,被声明为 final 的方法不可以被 override B 错在顺序问题很重要, final 不能写在 void 后面, C 严格的说也不可以被 override ,但可以被隐匿。类似 override 。所以也是错的。 E 错在: final 是防止 override 的,而 abstract 必须要被 override ,两个关键字不能连用。
64 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
You need to insert an inner class declaration at line3. Which two inner class declarations are valid? (Choose Two)
1.public class OuterClass{
2.private double d1=1.0;
3.//inser code here
}
A. static class InnerOne{
    public double methoda(){return d1;}
B. static class InnerOne{
     static double methoda(){return d1;}
C. private class InnerOne{
    public double methoda(){return d1;}
D. protected class InnerOne{
     static double methoda(){return d1;}
E. public abstract class InnerOne{
   public abstract double methoda();
 
Answer: c,e
A B D 错在,静态内类相当于一个静态方法,所以在静态方法中不能访问非静态成员。
 
65
You want a class to have access to members of another class in the same
package which is the most restrictive access modifier that will accomplish
this objective?
A. public
B. private
C. protected
D. transient
E. No acess modifier is required
 
题目的意思为在一个相同的包中,想让一个类能够引用另一个类的成员,而要用最大的局限性,也就是说要最小的访问控制权限来达到目的,要怎么办,题意弄清了之后,这道题也没什么可说的了。
Answer: e
 
66
 which two statements declare an array capable of 10 int?
A. int[] foo;
B. int foo[];
C. int foo[10];
D. Object[] foo;
E. Object foo[10];
 
Answer: a,b
要声明为 int 的,所以 CDE 都不对。
 
67
public class SwitchTest{
 public static void main(String[] args){
3) System.out.println("value="+switchIt(4));
 }
public static int switchIt(int x){
   int j=1;
switch(x){
 case 1: j++;
 case 2: j++;
 case 3: j++;
 case 4: j++;
 case 5: j++;
 default: j++;
 }
 return j+x;
 }
 }
 what is the output from line 3?
 A. value=3 B. value=4 C. value=5 D. value=6 E. value=7 F. value=8
Answer: F 程序从 case 4 开始执行,一直到结束。
68 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
 
which will declare a method that is available to all members of the same package and can be referenced without an instance of the class?
A. abstract public void methoda();
B. public abstract double methoda();
C. static void methoda(double d1){}
D. public native double methoda(){}
E. protected void methoda(double d1){}
 
Answer: c
69
1) public class SuperClass{
2) class SubClassA extends SuperClass{}
3) class SubClassB extends SuperClass{}
4) public void test(SubClassA foo){
5)     SuperClass bar=foo;
6)     }
7)     }
which statement is true about the assignment in line 5?
A. The assignment in line 5 is illegal
B. The assignment in line 5 is legal, but throw a ClassCastException
C. legal and will always executes without throw an Exception    
 
  
Answer: c
子类的对象可以被赋值给超类的对象。
70 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
 
which two are true to describe an entire encapsulation class?
 A. member data have no access modifiers
 B. member data can be modified directly
 C. the access modifier for methods is protected
 D. the access modifier to member data is private
 E. methods provide for access and modification of data
 
Answer: d,e
71 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
 
 public class X implements Runnable{
 public static void main(String[] args){
3)     //insert code
   }
 public void run(){
     int x=0,y=0;
     for(;;){
      x++;
      Y++;
   System.out.println("x="+x+",y="+y);
      }
     }
 }     
You want to cause execution of the run method in a new thread of execution.
Which line(s) should be added to the main method at line 3?
A. X x=new X();
   x.run();
B. X x=new X();
   new Thread(x).run();
C. X x=new X();
   new Thread(x).start();
D. Thread t=new Thread(x).run();
E. Thread t=new Thread(x).start();
 
Answer: a,c
72.
which gets the name of the parent directory of file "file.txt"?
 A. String name=File.getParentName("file.txt");
 B. String name=(new File("file.txt")).getParent();
 C. String name=(new File("file.txt")).getParentName();
 D. String name=(new File("file.txt")).getParentFile();
 E. Diretory dir=(new File("file.txt")).getParentDir();
String name=dir.getName();
 
Answer: b
73
The file "file.txt" exists on the file system and contains ASCII text.
 try{
   File f=new File("file.txt");
   OutputStream out=new FileOutputStream(f);
   }catch (IOException e){}
 A. the code does not compile
 B. the code runs and no change is made to the file
 C. the code runs and sets the length of the file to 0
 D. An exception is thrown because the file is not closed
 E. the code runs and deletes the file from the file system
 
Answer: c
 
 
74 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
 
The file “file.txt” exists on the file system and contains ASCII text.
Given:
38. try {
39. File f = new File(“file.txt”);
40. OutputStream out = new FileOutputStream(f, true);
41. }
42. catch (IOException)    {}
What is the result?
A.     The code does not compile.
B.     The code runs and no change is made to the file.
C.     The code runs and sets the length of the file to 0.
D.     An exception is thrown because the file is not closed. 
E.     The code runs and deletes the file from the file system.
 
Answer :A
 
 
75 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
 
 class Super{
 public int i=0;
 public Super(String text){
 i=1;
 }
 }
 public class Sub extends Super{
    public Sub(String text){
     i=2;
    }
 public static void main(String args[]){
   Sub sub=new Sub("Hello");
   System.out.println(sub.i);
   }
   }
 what is the result?     
   A. compile will fail
   B. compile success and print "0"
   C. compile success and print "1"
   D. compile success and print "2"
 
Answer:   a
超类中缺少无参构造器,所以编译错误。
 
76 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
 
 import java.io.IOException;
   public class ExceptionTest{
   public static void main(String args[]){
    try{
        methodA();
       }catch(IOException e){
       System.out.println("Caught Exception");
       }
       }
    public void methodA(){
     throw new IOException();
     }
     }
    what is the result?
    A.The code will not compile
    B.The output is Caught Exception
    C.The output is Caught IOException
    D.The program executes normally without printing a message
 
Answer: a
首先, methodA 是非静态方法,不能出现在 main 中,其次,就算 methodA 是静态方法, IOException 是可检测异常,必须要被 catch 捕获或是被 throws 声明,但程序中没声明 (throws) ,所以 try 语句体永远也不可能抛出 IOException 这个异常,而 catch 也就谈不到捕获它了,所以两个条件都没有满足,所以编译同样错误。
methodA 方法的定义语句后面加上 throws IOException 就对了。
 
77 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
 
You are assigned the task of building a Panel containing a TextArea at the top, a Labbel directly bellow it, and a Button directly bellow the Label. If the three components added directly to the Panel. which layout manager can the Panel use to ensure that the TextArea absorbs all of the free vertical space when the Panel is resized?
   A.GridLayout
   B.CardLayout
   C.FlowLayout
   D.BorderLayout
   E.GridbagLayout
 
Answer: e
 
78  
You need to store elements in a collection that guarantees that no duplicates are stored and all elements can be access in nature order, which interace provides that capability?
 A. java.uil.Map
 B.java.util.Set
 C.java.util.List
 D.java.util.SortedSet
 E.java.util.SortedMap
 F.java.util.Collection
 
Answer: B
set 为最佳答案。
79
 which two cannot directly cause a thread to stop executing?
A.calling the yield method
B.calling the wait method on an object
C.calling the notify method on an object
D.calling the notifyAll method on an object   
E.calling the start method on another thread object
 
Answer: C,D
注意cannot 这个词呀,不要大意了。
当用 yield 的时候,线程会停止执行。当用 wait 的时候,线程进行 wait 状态,当然 stop 啦,所以 A B 都不对,当调用 start 方法启动另一个线程时,线程只是进行 ready 状态,并不能保证 CPU 马上就会给这个线程机会运行,而停止当前正在运行的线程,但也可能替换掉当前的线程,这个说不准,所以也不对。
所以 A B E 都会或是可能会停止当前正在运行的线程,而只有 C D 这两个白痴方法不具备这种功能。
 
80 Which two CANNOT directly cause a thread to stop executing? (Choose Two)
 
A.Existing from a synchronized block
B.Calling the wait method on an object
C.Calling notify method on an object
D.Calling read method on an InputStream object
E.Calling the SetPriority method on a Thread object
 
ANSWER:A,C
 
81
Which two can directly cause a thread to stop executing? (Choose Two)
A. Exiting from a synchronized block.
B. Calling the wait method on an object.
C. Calling the notify method on an object.
D. Calling the notifyAll method on an object.
E. Calling the setPriority method on a thread object.
 
Answer: B, E
 
 
 
82
1. public class Foo implements Runnable (
2. public void run (Thread t) {
3. system.out.printIn(“Running.”);
4. }
5. public static void main (String[] args) {
6. new thread (new Foo()).start();
7. )
8. )
 what is the result?
 A.An Exception is thrown
 B.The program exits without printing anything
 C.An error at line 1 causes complication to fail
 D.An error at line 2 causes complication to fail
 E."Running" is pinted and the program exits
 
Answer: C
Runnable 接口中只有一个 run 方法,而且是 public void 和无参的,实现这个接口必须实现 run 方法,这里的 run 是有参的,因此这里实际上并没有实现 public void run() ,而创建了一个新的方法,所以 Start() 不会自动调用,系统提示 C: 第一句有错!认为 run 方法没有被实现。
 
83
which method in the Thread class is used to create and launch a new thread of execution?
A.run()     B.start()   C. begin()   D.run(Runnable r) E.execute(Thread t)
 
Answer: b
 
84 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
 
which is true?
A.If only one thread is blocked in the wait method of an object, and another thread executes the notify method on that same object,then the first thread immediately resumes executes.
B. If a thread is blocked in the wait method of an object, and another thread executes the notify method on the same object,it is still possible that the first thread might never resume execution
C.If a thread is blocked in the wait method of an object,and another thread executes the notify method on the same object,then the first thread definitely resumes execution as a direct and sole consequence of the notify call
D.If two threads are blocked in the wait method of one object,and another thread executes the notify method on the same object,then the thread that executed the wait call first definitely resumes execution as a direct and sole consequence of the notify call
 
Answer: b
 
85 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
 
which statement is true?
A. An anonymous inner class may be declared as final
B. An anonymous inner class can be declared as private
C. An anonymous inner class can implement mutiple interfaces
D. An anonymous inner class can access final variables in any enclosing scope
E. Construction of an instance of a static inner class requires an instance of the encloing outer class
 
 
Answer: d
 
86 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  
1. public class X {
2. public object m () {
3. object o = new float (3.14F);
4. object [] oa = new object [1];
5. oa[0]= o;
6. o = null;
7. oa[0] = null;
8.return o;
9. }
10. }
 when is the float Object, created in line 3 ,collected as garbage?
 A.just after line 5 B.just after line 6 C.just after line 7    D.never in this method
 
Answer: C
在第六行时,虽然 o=null ,但同时 oa[0] 还指向 o 的内存区域,在第七行时, oa[0]=null 时,就没有对象再指向 o 的内存区域了,所以满足了垃圾收集的条件。
 
 
 
87
 //point X
public class Foo{
public static void main(String[] args){
PrintWriter out=new PrintWriter(new java.io.OutputStreamWriter(System.out),true);
out.println("Hello");
 }
 }
which statement at point X on line 1 allows this code to compile and run?
A.import java.io.PrintWriter          B.include java.io.PrintWriter
C.import java.io.OutputStreamWriter    D.include java.io.OutputStreamWriter
E.No statement is needed
 
Answer: a
在程序开头要导入,所以选A ,在程序中,OutputStreamWreter 使用了 java.io.OutputStreamWriter 这种形式,所以程序开头不用导入。 include ????这东东好像和 java 半点关系都没有耶。
 
88
 Given:
1. //point X
2. public class foo (
3. public static void main (String[]args) throws Exception {
4. java.io.printWriter out = new java.io.PrintWriter (
5. new java.io.outputStreamWriter (System.out), true;
6. out.printIn(“Hello”);
7. }
8. }
 
Which statement at PointX on line 1 allows this code to compile and run?
A. import java.io.*;
B. include java.io.*;
C. import java.io.PrintWriter;
D. include java.io.PrintWriter;
E. no statement is needed.
 
Answer : E
对比一下就知道了呗.
 
89
 which prevent create a subclass of outer class?
 A.static class FooBar{}
 B.pivate class Foobar{}
 C.abstract class FooBar{}
 D.final public class FooBar{}
 E.final abstract class FooBar{}
 
Answer: d
final 防止继承!不可以和 abstract 连用!!!
90
1)abstract class AbstractIt{
 2) abstract float getFloat();
 3) }
 4) public class AbstractTest extends AbstractIt{
 5) private float f1=1.0f;
 6) private float getFloat(){return f1;}
 7) }
 what is the result?
 
Answer: compile error
为抽象的方法提供了具体的实现,可问题出现在private 这个东东上。
 
91
byte[] array1,array2[]
byte array3[][]
byte[][] array4
if each has been initialized, which statement will cause a compile error?
A. array2 = array1;
B. array2 = array3;
C. array2 = array4;
D. both A and B
E. both A and C
F. both B and C
 
 
Answer: a
这里要注意一个数组的维数的问题。围数必须相同 , 不能把小的给大的 , 也不能把大的给小的 . 但这不是这道题的关键,这道题的关键是 byte[] array1,array2[] ,嘿嘿,看懂了吗?它实际是上 byte[]array1 byte[]array[] 两个耶,写个通俗的形式就是 byte array1[] byte array2[][] ,这样子这道题就不难了吧。
92 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
What writes the text “” to the end of the file “file.txt”?
A. OutputStream out= new FileOutputStream (“file.txt”);
Out.writeBytes (“/n”);
B. OutputStream os= new FileOutputStream (“file.txt”, true);
DataOutputStream out = new DataOutputStream(os);
out.writeBytes (“/n”);
C. OutputStream os= new FileOutputStream (“file.txt”);
DataOutputStream out = new DataOutputStream(os);
out.writeBytes (“/n”);
D. OutputStream os= new OutputStream (“file.txt”, true);
DataOutputStream out = new DataOutputStream(os);
out.writeBytes (“/n”);
 
Answer B
 
 
93
 which constructs a DataOutputStream ?
A.new DataOutputStream("out.txt");
B.new DataOutputStream(new File("out.txt"));
C.new DataOutputStream(new Writer("out.txt"));
D.new DataOutputStream(new OutputStream("out.txt"));
E.new DataOutputStream(new FileWriter("out.txt"));
F.new DataOutputStream(new FileOutputSream("out.txt"));
 
Answer: f
94
which statement is true for the class java.util.HashSet?
A.The elements in the collection are ordered
B.The collection is guaranteed to be immutable
C.The elements in the collection are guaranteed to be unique
D.The elements in the collection are access using a unique key
E.The elements in the collection are guaranteed to be synchronized
 
 
Answer: c
95
1) public abstract class Test{
 2) public abstract void methodA();
 3) public abstract void methodB()
 4) { System.out.println("Hello");
 5) }
 6) }
 which three changes(made independently) allow the code to compile?
 A.add a method body to methodA.
 B.replace line 4-5 with a ";".
 C.remove the abstract qualifier from the declaration of Test.
 D.remove the abstract qualifier from the declaration of methodB.
 E.remove the abstract qualifier from the declaration of methodA.
 F.remove methodB in its entirety and change class to interface in line 1.
 
Answer: bdf
问题的关键 methodB 是一个抽象方法,不能够提供具体的实现,但提供了具体的实现,
所以解决办法也就围绕着 methodB 来想呗。
methodB 方法中的实现去掉,换成分号,当然可以啦。所以 B 正确。
D 的意思是把 abstract 去掉,这样 mehtodB 就成了一个普通的方法,虽然类 Test 是抽象的,但在抽象类中允许普通方法存在,所以也对。
F 的意思是整个把 methodB 删掉,哈哈,这样最保险了。但它还说把类改成一个接口,我认为这没有必要。
A C E 都没有解决关键的问题,当然也就不对了。
 
96
ClassOne.java
package com.ab.pkg1;
 public class ClassOne{
 private char var='a';
 char getVar(){ return var;}
    }
 
ClassTest.java
 package com.ab.pkg2;
 import com.ab.pkg1.ClassOne;
 public class ClassTest extends ClassOne{
   public static void main(String args[]){
    char a=new ClassOne().getVar();
    char b=new ClassTest().getVar();
 }
 }
what is the result?
A. Compilation will fail.
B. Compilation succeeds and no exceptions are thrown.
C. Compilation succeeds but an exception is thrown at line 5 in ClassTest.java.
D. Compilation succeeds but an exception is thrown at line 6 in ClassTest.java.
 
Answer: B
 
97
int i=1,j=10;
 do{
    if(i>j)continue;
    j--;
    }while(++i<6);
 what are the vale of i and j?
 A.i=6,j=5
 B.i=5,j=5
 C.i=6,j=4
 D.i=5,j=6
 E.i=6,j=6
 
Answer: A
这种题我觉得有一些难度,这道题的问题是当 i=5 j= 多少,因为 i=6 或是 i>6 时循环。就退出了。当 i=1 时, j=10 ,但当 while 重新判断时, j-- 就被执行,所以第一次循环结束而第二次循环未开始时 i=1 j=9 ,这样当 i=5 时, j=5 ,这里进行 while 判断,因为是 ++i ,所以 i 在使用之前加 1 i 变成了 6 ,所以选 A 正确。
98
1)public class Foo{
 2)public static void main(String[] args){
 3)int i=1;
 4) int j=i++;
 5) if((i>++j)&&(i++==j)){
 6)      i+=j;
       }
       }
      }
 what is the final value i and j?
 
Answer: i=2,j=2
第四行时,i 的值是先赋给了j 然后再进行++ 计算的,所以此时i=2,j=1 ,第五行判断,++j 是先自加1 ,然后再使用的,所以j+1=2 后,再和i 比较,当然结果是flase ,又因为是&& ,所以后半句i++==j 不执行,所以i=2,j=2.
99
 which two are equivalent?
A.16>4
B.16/2
C.16*4
D.16>>2
E.16/2^2
F.16>>>2
 
A=true;
B=8;
C=64;
D=4,>> 就是除以 2 n 次方, n 是要移的位数。左移就是乘
E=10
F=4
Answer: d,f
100
public class X{
 public static void main(String[] args){
   byte b=127;
4) byte c=126;
5) byte d=b+c;
 }
 }
A.Compilation succeeds and d takes the value 253.
B.Line 5 contains an error that prevents compilation.
C.Line 5 throws an exception indicating “Out of range”.
D.Line 3 and 4 contain error that prevent compilation.
E.The compilation succeeds and d takes the value of 1.
 
Answer: B
byte 的范围可是-128 到+127 耶!看清楚了。
 
101
AnInterface is an interface
AnAdapter0 is a non-abstract,non-final class with a zero argument constructer
AnAdapter1 is a non-abstract,non-final class without a zero argument constructer,but with a constructer that takes one int argument
which two creat an anoymous inner class?
A.AnAdapter0 aa=new AnAdapter0(){}
B.AnAdapter1 aa=new AnAdapter1(5){}
C.AnAdapter1 aa=new AnAdapter1(){}
D.AnAdapter0 aa=new AnAdapter0(5){}     
E.AnInterface ai=new AnInterface(5){}
 
Answer: a,b
有有参的构造器就传参数,有无参的构造器就不能传参数。
102 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
 which two creat an InputStream and open the file"file.txt" for reading?
A. InputStream in=new FileReader(“file.txt”);
B. InputStream in=new FileInputStream(“file.txt”);
C. InputStream in=new InputStreamFileReader (“file.txt”, “read”);
D. FileInputStream in=new FileReader(new File(“file.txt”));
E. FileInputStream in=new FileInputStream(new File(“file.txt”));
 
Answer: B,E
103 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Which two construct an OutputSream that appends to the file “file.txt”? (Choose Two)
A. OutputStream out=new FileOutputStream(“file.txt”);
B. OutputStream out=new FileOutputStream(“file.txt”, “append”);
C. FileOutputStream out=new FileOutputStream(“file.txt”, true);
D. FileOutputStream out=new FileOutputStream(new file(“file.txt”));
E. OutputStream out=new FileOutputStream(new File(“file.txt”)true);
 
Answer:C,E
 
 
104 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
which constructs a BuferedInputStream?
A. New BufferedInputStream(“in.txt”);
B. New BufferedInputStream(new File(“in.txt”));
C. New BufferedInputStream(new Writer(“in.txt”));
D. New BufferedInputStream(new Writer(“in.txt”));
E. New BufferedInputStream(new InputStream(“in.txt”));
F. New BufferedInputStream(new FileInputStream(“in.txt”));
 
Answer: F
 
105 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Which can be used to encode charS for output?
 
A. java.io.OutputStream
B. java.io.OutputStreamWriter
C. java.io.EncodeOutputStream
D. java.io.EncodeWriter
E. java.io.BufferedOutputStream
  
 
Answer: B
 
106 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Which can be used to decode charS for input?
A. java.io.InputStream
B. java.io.EncodedReader
C. java.io.InputStreamReader
D. java.io.InputStreamWriter
E. java.io.BufferedInputStream
 
Answer C
107 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
which determines if "prefs" is a directory and exist on the file system?
 
 
A.Boolean exists=Directory.exists (“prefs”);
B.Boolean exists=(new File(“prefs”)).isDir();
C.Boolean exists=(new Directory(“prefs”)).exists();
D.Boolean exists=(new File(“prefs”)).isDirectory();
E.Boolean exists=true;
Try{
 Directory d = new Directory(“prefs”);
}
catch (FileNotFoundException e) {
   exists = false;
}
 
Answer: D
108
which code determines the int value foo closest to, but not greater than, a double value bar?
 A.int foo=(int)Math.max(bar);
 B.int foo=(int)Math.min(bar);
 C.int foo=(int)Math.abs(bar);
 D.int foo=(int)Math.ceil(bar);
 E.int foo=(int)Math.floor(bar);
 F.int foo=(int)Math.round(bar);
 
 
Answer:   e
109 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Which code determines the int value foo closest to a double value bar?
A. Int foo = (int) Math.max(bar);
B. Int foo = (int) Math.min(bar);
C. Int foo = (int) Math.abs(bar);
D. Int foo = (int) Math.ceil(bar);
E. Int foo = (int) Math.floor(bar);
F. Int foo = (int) Math.round(bar);
 
Answer: F
110 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
import java.awt.*;
 public class Test extends Frame{
 public Test(){
    add(new Label("Hello"));
    add(new TextField("Hello"));
    add(new Button("Hello"));
    pack();
  show();}
 public static void main(String[] args){
 new Test();
 }
 }   
what is the result? 
 
A. The code will not compile.
B. A Window will appear containing only a Button.
C. An IllegalArgumentException is thrown at line 6.
D. A Window button will appear but will not contain the Label, TextField, or Button.
E. A Window will appear containing a Label at the top, a TextField below the Label, and a Button below the TextField.
F. A Window will appear containing a Label on the left, a TextField to the right of the Label, and a button to the right of the TextField.
 
Answer:B 覆盖 , 框架出现 , 只包含按钮  
 
111 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
 which is true?
A. The Error class is a RuntimeException.
B. No exceptions are subclasses of Error.
C. Any statement that may throw an Error must be enclosed in a try block.
D. Any statement that may throw an Exception must be enclosed in a try block.
E. Any statement that may thro a runtimeException must be enclosed in a try block.
 
Answer: d
 
112 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Which statement about static inner classes is true?
    A.An anonymous class can be declared as static.
    B.A static inner class cannot be a static member of the outer class.
    C.A static inner class does require an instance of the enclosing class.
    D.Instance member of a static inner class can be referened using the class name of the static inner class.
 
Answer: A
 
113
public class MyCircle{
    public double radius;
   public double diameter;
   public void setRadius(double radious){
 6) this.radius=radius;
 7) this.diameter=radius*2;}
public double getRadius(){
return radius;
}
}
A. The MyCircle class is fullly encapsulated
B. The diameter of a given MyCircle is guaranteed to be twice its radius.
C. Line 6 and 7 should be in a Synchronized block to ensure encapsulation.
D. The radius of a MyCircle object can be set without affecting its diameter.
 
Answer: B
114
Given:
public class ArrayList{
 public static void main(String[] args){
 float f1[],f2[];
 f1=new float[10];
 f2=f1;
 System.out.println("f2[0]="+f2[0]);
 }
 }
 what is the result?
A. It prints f2[0] = 0.0.
B. It prints f2[0] = NaN.
C. An error at line 5 causes compile to fail.
D. An error at line 6 causes compile to fail.
E. An error at line 6 causes an exception at runtime.
 
Answer: A
本题中这样的给数组赋值是合法的。
115
public class X{
 public static void main(String[] args){
   int[] a=new int[1];
 4) modify(a);
   System.out.println(a[0]);
   }
   public static void modify(int[] a){
 9) a[0]++;}
    }
 what is the result?
 A.The program runs and prints "0";
 B.The program runs and prints "1";
 C.The program runs but aborts with an exception;
 D.An error "possible undefined variable" at line 4 cause compilation to fail;
 E.An error "possible undefined variable" at line 9 cause compilation to fail;
 
Answer: b
数组也是对象,所以传值时发生改变。
 
117
Given:
Integer i = new Integer (42);
Long 1 = new Long (42);
Double d = new Double (42.0);
Which two expressions evaluate to True? (Choose Two)
A.     (i ==1)
B.     (i == d)
C.     (d == 1)
D.     (i.equals (d))
E.     (d.equals (i))
F.     (i.equals (42))
 
 
Answer:F
== ”两边的类型必须一样,所以 A B C 都不对,
equals ()”被类型包装类覆盖,当两边类型相同时,对象所代表的基本类型的值相等,则返回真,对象类型不同时,即使代表的基本类型的值相等,也返回假。所以 D,E 也不对,
118
Given:
1. public class MethodOver {
2.      public void setVar (int a, int b, float c) {
3.      }
4. }
 
Which two overload the setVar method? (Choose Two)
A. private void setVar (int a, float c, int b) { }
B. protected void setVar (int a, int b, float c) { }
C. public int setVar (int a, float c, int b) (return a;)
D. public int setVar (int a, int b, float c) (return a;)
E. protected float setVar (int a, int b, float c) (return c;)
 
Answer A,C
又是 overload ,唉呀我不说了,自己看吧,在前边我已经说过 n 次了。不过有一点应该提醒一下,就是 overload 没有访问控制限制。
119
Given:
1. class BaseClass {
2.     Private float x = 1.0f ;
3.      protected float getVar ( ) ( return x;)
4. }
5. class Subclass extends BaseClass (
6.        private float x = 2.0f;
7.        //insert code here
8. )
 
Which two are valid examples of method overriding? (Choose Two)
A. float getVar ( ) { return x;}
B. public float getVar ( ) { return x;}
C. float double getVar ( ) { return x;}
D. protected float getVar ( ) { return x;}
E. public float getVar (float f ) { return f;}
 
Answer B,D
120 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Which two demonstrate an “is a” relationship? (Choose Two)
 
A. public interface Person { }
public class Employee extends Person { }
B. public interface Shape { }
public class Employee extends Shape { }
C. public interface Color { }
public class Employee extends Color { }
D. public class Species { }
public class Animal (private Species species;)
E. interface Component { }
Class Container implements Component (
         Private Component[ ] children;
 
 
Answer D,E
is a 是继承的关系, has a 是调用的关系。
121 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Given:
1. package foo;
2. 
3. public class Outer (
4.     public static class Inner (
5.     )
6. )
 
Which statement is true?
A. An instance of the Inner class can be constructed with “new Outer.Inner ()”
B. An instance of the inner class cannot be constructed outside of package foo
C. An instance of the inner class can only be constructed from within the outer class
D. From within the package bar, an instance of the inner class can be constructed with “new inner()”
 
 
Answer A
122    
 Given:
8.    int index = 1;
9.    boolean[] test = new boolean[3];
10. boolean foo= test [index];
 
What is the result?
A. foo has the value of 0
B. foo has the value of null
C. foo has the value of true
D. foo has the value of false
E. an exception is thrown
F. the code will not compile
 
Answer D
boolean 数组的默认值是 false
123
 Given:
1. public class test(
2.    public static void main(String[]args){
String foo = args [1];
4.                 String foo = args [2];
5.                   String foo = args [3];
6.       
 
}
7. }
 
And the command line invocation:
Java Test red green blue
What is the result?
A. baz has the value of “”
B. baz has the value of null
C. baz has the value of “red”
D. baz has the value of “blue”
E. bax has the value of “green”
F. the code does not compile
G. the program throws an exception
 
Answer F
无法编译,foo 重复定义.
124
Which will declare a method that forces a subclass to implement it?
 
A. Public double methoda();
B. Static void methoda (double d1) {}
C. Public native double methoda();
D. Abstract public void methoda();
E. Protected void methoda (double d1){}
 
Answer D
强迫子类实现耶,当然是 abstract 啦。
125
You want subclasses in any package to have access to members of a superclass. Which is the most restrictive access modifier that will accomplish this objective?
 
A. Public
B. Private
C. Protected
D. Transient
E. No access modifier is qualified
 
Answer:C
126
 Given:
1. abstract class abstrctIt {
2. abstract float getFloat ();
3. )
4. public class AbstractTest extends AbstractIt {
5. private float f1= 1.0f;
6. private float getFloat () {return f1;}
7. }
 
What is the result?
A. Compilation is successful.
B. An error on line 6 causes a runtime failure.
C. An error at line 6 causes compilation to fail.
D. An error at line 2 causes compilation to fail.
 
Answer:C
override 的方法不能更加私有化。
127
Click the exhibit button:
1.  public class test(
2.  public int aMethod(){
3. static int i=0;
4.  i++;
5.  return I;
6.  )
7.  public static void main (String args[]){
8.  test test = new test();
9.  test.aMethod();
10. int j = test.aMethod();
11. System.out.printIn(j);
12. }
13. }     
 
What is the result?
A. Compilation will fail.
B. Compilation will succeed and the program will print “0”.
C. Compilation will succeed and the program will print “1”.
D. Compilation will succeed and the program will print “2”.
 
 
Answer A
问题出现在第 3 行,静态变量属于类 , 不能在方法中定义 .
 
128.
Which is a method of the MouseMotionListener interface?
 
A. Public void mouseMoved(MouseEvent)
B. Public boolean mouseMoved(MouseEvent)
C. Public void mouseMoved(MouseMotionEvent)
D. Public boolean MouseMoved(MouseMotionEvent)
E. Public boolean mouseMoved(MouseMotionEvent)
 
Answer:A
129 Which is a method of the MouseMotionListener interface?
A. Public void mouseDragged(MouseEvent)
B. Public boolean mouseDragged(MouseEvent)
C. Public void mouseDragged(MouseMotionEvent)
D. Public boolean MouseDragged(MouseMotionEvent)
E. Public boolean mouseDragged(MouseMotionEvent)
Answer : A
这两道题连起来看, MouseMotionListener 有多个构造器。但全都是 public void 的,而且需要一个 MouseEvent 类型的参数。
 
 
130 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
 Click the exhibit button:
1. import java.awt.*;
2.   
3. public class X extends Frame (
4. public static void main(string []args) (
5. X x = new X ();
6. x.pack();
7. x.setVisible(true);
8. )
9.   
10. public X () (
11. setlayout (new GridLayout (2,2));
12.   
13. Panel p1 = new panel();
14. Add(p1);
15. Button b1= new Button (“One”);
16. P1.add(b1); 
17.   
18. Panel p2 = new panel();
19. Add(p2);
20. Button b2= new Button (“Two”);
21. P2.add(b2);
22.   
23. Button b3= new Button (“Three”);
24. add(b3);
25.   
26. Button b4= new Button (“Four”);
27. add(b4);
28.      )
29. )
 
Which two statements are true? (Choose Two)
A. All the buttons change height if the frame height is resized.
B. All the buttons change width if the Frame width is resized.
C. The size of the button labeled “One” is constant even if the Frame is resized.
D. Both width and height of the button labeled “Three” might change if the Frame is resized.
 
Answer C,D
测试一下就明白了,画得好难看呀 ~~~~~~~~~ ,唉,凑合啦,没办法
 
      one                   two
     
      three
  
     four
 
 
 
 
 
 
 
131
Given:
1. public class IfTest (
2. public static void main(string[]args) {
3. int x = 3;
4. int y = 1;
5. if (x = y)
6. system.out.printIn(“Not equal”);
7. else
8. system.out.printIn(“Equal”);
9. }
10. )
 
What is the result?
A. The output is “Equal”.
B. The output in “Not Equal”.
C. An error at line 5 causes compilation to fall.
D. The program executes but does not print a message.
 
Answer: C
x=y 的运算结果不是boolean 类型的, 所以错.
132
Click the exhibit button:
1. public class test (
2. public static void main(string args[]) {
3. int i= 0;
4. while (i) {
5. if (i==4) {
6. break;
7. )
8. ++i;
9. )
10.   
11. )
12. )
 
What is the value of i at line 10?
A. 0
B. 3
C. 4
D. 5
E. the code will not compile
 
Answer: E
和上一题一样,各种循环的判别式都必须是布尔型的,除了 switch
133
Given:
1. switch (i) {
2. default:
3. System.out.printIn(“Hello”);
4. )
 
What are the two acceptable types for the variable i? (Choose Two)
A. char
B. byte
C. float
D. double
E. object
 
Answer :A,B
刚说到 switch ,它就来了,这里的 i 可以是 char 或是 int byte short 因为当进入 switch 的时候 ,JVM 会把 i 转换成 int, 所以其它的类型都会出现精度损失的情况 . 所以如果把上题中的 switch 语句改成 (int)i, 这样就什么类型都可以啦 .
134.
Which two can be used to create a new Thread? (Choose Two)
A. Extend java.lang.Thread and override the run method.
B. Extend java.lang.Runnable and override the start method.
C. Implement java.lang.thread and implement the run method.
D. Implement java.lang.Runnable and implement the run method.     
E. Implement java.lang.Thread and implement the start method.
 
Answer:A,D
 
 
135.
Click the exhibit button:
1. public class SyncTest{
2. public static void main(String[] args) {
3. final StringBuffer s1= new StringBuffer();
4. final StringBuffer s2= new StringBuffer();
5. new Thread ()    {
6.    public void run() {
7.     synchronized(s1) {
8.          s2.append(“A”);
9.           synchronized(s2) {
10.    s2.append(“B”);
11.      System.out.print(s1);
12.        System.out.print(s2);
13.        }
14.    }
15.    }  
16. }.start();
17. new Thread() {
18.    public void run() {
19.      synchronized(s2) {
20.        s2.append(“C”);
21.        synchronized(s1) {
22.          s1.append(“D”);
23.          System.out.print(s2);
24.          System.out.print(s1);
25.         }
26.        }
27.       }
28.     }.start();
29.    }
30. }
 
Which two statements are true? (Choose Two)
A. The program prints “ABBCAD”
B. The program prints “CDDACB”
C. The program prints “ADCBADBC”
D. The output is a non- deterministic point because of a possible deadlock condition
E. The output is dependent on the threading model of the system the program is running on.
 
ANSWER:D,E
136
 Given:
5. String foo = “base”;
6. foo.substring(0,3);
7. foo.concat(“ket”)
8. 
 
Type the value of foo at line 8.
 
Ans:   base
137
Given:
1. String foo = “base”;
2. foo.substring(0,3);
3. foo.concat(“ket”);
4. foo += “ball”;
5.
Type the value of foo at line 8.
 
Answer: BASEBALL
这两道题连起来看,根据 String 的不变性,在前三条语句执行后,两题中的 foo 都没变,但两条语句都产生了一个新的字符串,不同的是 137 多的那条语句, 137 的第 4 条语句不但创建了一个新的字符串,还把它显示的赋给了 foo
138 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Which statement is true?
A. A flow layout can be used to position a component that should resize horizontally when the container is resized.
B. A grid layout can be used to position a component that should maintain a constant size even when the container is resized.
C. A border layout can be used to position a component that should maintain a constant size even when the container is resized.
D. The grid bag layout can be used to give a grid-like layout which differs from the normal grid in that individual rows and columns can have unique sizes.
E. If two components are placed in the same column of a grid bag layout, and one component resizes horizontally, then the other component must resize horizontally.
 
Answer:D
139
Given:
1. class BaseClass{
2. private float x= 1.0f;
3. protected void setVar (float f) {x = f;}
4. }
5. class SubClass exyends BaseClass    {
6. private float x = 2.0f;
7. //insert code here
8. }
 
Which two are valid examples of method overriding? (Choose Two)   
A. void setVar(float f) {x = f;}
B. public void setVar(int f) {x = f;}
C. public void setVar(float f) {x = f;}
D. public double setVar(float f) {x = f;}
E. public final void setVar(float f) {x = f;}
F. protected float setVar() {x=3.0f; return 3.0f; }
 
Answer:C,E
注意防问控制权限,注意返回类型,注意参数表列,而且可以加final 呀。还有,注意这道题是overrid 不是overload
140
Click the exhibit button:
1. class A {
2. public byte getNumber () {
3.    return 1;
4.    }
5. }
6.   
7. class B extends A {
8. public short getNumber() {
9. return 2;
10. )
11.   
12. public static void main (String args[]) { 
13.     B b = new B ();
14.       System.out.printIn(b.getNumber())   
15.    }
16. }
 
What is the result?
A. Compilation succeeds and 1 is printed.
B. Compilation succeeds and 2 is printed.
C. An error at line 8 causes compilation to fail.
D. An error at line 14 causes compilation to fail.
E. Compilation succeeds but an exception is thrown at line 14.
 
Answer:C
这道题不是 overload ,也不是 override ,那就错的呗。
141 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
 Which two statements are true? (Choose Two)
A. An inner class may be declared as static
B. An anonymous inner class can be declared as public.
C. An anonymous inner class can be declared as private.
D. An anonymous inner class can extend an abstract class.
E. An anonymous inner class can be declared as protected.
 
Answer: A,B
142 You want to limit access to a method of a public class to members of the same class. Which access modifier accomplishes this objective?
 
A. Public
B. Private
C. Protected
D. Transient
E. No access modifier is required
 
Answer:B
 
143
 Which two statements are true regarding the creation of a default constructor? (Choose Two)
A. The default constructor initializes method variables.
B. The compiler always creates a default constructor for every class.
C. The default constructor invokes the no-parameter constructor of the superclass.
D. The default constructor initializes the instance variables declared in the class.
E. When a class has only constructors with parameters, the compiler does not create a default constructor.
 
Answer:D,E
144 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@`  
Which two statements are true regarding the creation of a default constructor? (Choose Two)
A. The default constructor initializes method variables.
B. The default constructor invokes the no-parameter constructor of the superclass.
C. The default constructor initializes the instance variables declared in the class.
D. If a class lacks a no-parameter constructor, but has other constructors, the compiler creates a default constructor.
E. The compiler creates a default constructor only when there are no other constructors for the class.
 
Answer C,E
145
 Click the exhibit button:
1. class super {
2.    public int getLength() {return 4;}
3. }
4.   
5. public class Sub extends Super {
6.     public long getLength() {return 5;}
7.   
8. public static void main (String[]args) {
9.           super sooper = new Super ();
10. Sub sub = new Sub();
11. System.out.printIn(
12.     sooper.getLength()+ “,” + sub.getLength()   };
13. }
14. }      
 
What is the output?
A. 4, 4
B. 4, 5
C. 5, 4
D. 5, 5
E. the code will not compile
 
Answer E
两个 getLength 方法既不是 override 也不是 overload
146.
 Which is a valid identifier?
 
A. false
B. default
C. _object
D. a-class
 
Answer C
147.
Click the exhibit button:
1. package foo;
2.   
3. import java.util.Vector;
4.   
5. private class MyVector extends Vector {
6. int i = 1;
7. public MyVector() {
8. i = 2;
9.     }
10. }
11.   
12. public class MyNewVector extends MyVector {
13. public MyNewVector () {
14. i = 4;
15. }
16. public static void main (String args []) {
17. MyVector v = new MyNewVector();
18.    }
19. } 
 
The file MyNewVector.java is shown in the exhibit.
What is the result?
A. Compilation will succeed
B. Compilation will fail at line 5
C. Compilation will fail at line 6
D. Compilation will fail at line 14
E. Compilation will fail at line 17
 
Answer:B
类只能加 public 或什么都不加。
148
Given:
1. public class Test {
2. public static void main (String[]args) {
3.    String foo = args[1];
4.    String bar = args[2];
5.    String baz = args[3];
6. System.out.printIn(“baz = ” + baz);
7.    }
8. }
 
And the output:
Baz = 2
Which command line invocation will produce the output?
A. java Test 2222
B. java Test 1 2 3 4
C. java Test 4 2 4 2
D. java Test 4 3 2 1
 
Answer C
149
 Given:
1. public interface Foo{
2. int k = 4;
3. }
 
Which three are equivalent to line 2? (Choose Three)
A.final int k = 4;
B.public int k = 4;
C.static int k = 4;
D.private int k = 4;
E.abstract int k = 4;
F.volatile int k = 4;
G.transient int k = 4;
H.protected int k = 4;
 
Answer:A,B,C
150
Which of the following two are valid declarations of a char? (Choose Two)
A.char ch = “a”;
B.char ch = ‘/’ ‘;
C.char ch = ‘cafe’;
D.char ch = “cafe”;
E.char ch = ‘/ucafe’;
F.char ch = ‘/u10100’;
G.char ch = (char) true;
 
Answer : B,E
char 型只能被赋一个字符或数字或一些符号,而且要用单引号,注意,它是字符,而不是字符串。
 
151
Click the exhibit button:
1. public class X {
2. public static void main (String[]args) {
3. String s1 = new String (“true”);
4. Boolean b1 = new Boolean (true);
5. if (s1.equals(b1))    {
6. System.out.printIn(“Equal”);
7.        }
8.       }
9.      }  
 
What is the result?
A. The program runs and prints nothing.
B. The program runs and prints “Equal.”
C. An error at line 5 causes compilation to fail.
D. The program runs but aborts with an exception.
 
Answer A
对于 equals ,即使两边对象的内容完全相同,但对象的类型不同时,也返回 flase
 
152. @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Click the exhibit button:
1. public class X {
2. public static void main (String[]args)    {
3. string s = new string (“Hello”);
4. modify(s);
5. System.out.printIn(s);
6. }
7.   
8. public static void modify (String s) {
9. s += “world!”; 
10.     }
11. }   
 
What is the result?
A.The program runs and prints “Hello”.
B.An error causes compilation to fail.
C.The program runs and prints “Hello world!”.
D.The program runs but aborts with an exception.
 
Answer :A
 
153.Given:
1. public class WhileFoo {
2. public static void main (String []args)    {
3. int x= 1, y = 6;
4. while (y--) {x--;}
5. system.out.printIn(“x=” + x “y =” + y);
6.     }
7. }
 
What is the result?
A.The output is x = 6 y = 0
B.The output is x = 7 y = 0
C.The output is x = 6 y = -1
D.The output is x = 7 y = -1
E.Compilation will fail
 
Answer:E
 
154.
 Click the exhibit button:
1. int I=1, j=0
2.   
3. switch(i) {
4. case 2:
5. j+=6;
6.   
7. case 4:
8. j+=1;
9.   
10. default:
11. j +=2;
12.   
13. case 0:
14. j +=4;
15. }
16.    
 
What is the value of j at line 16?
A. 0
B. 1
C. 2
D. 4
E. 6
 
Answer : E
155.
You need to store elements in a collection that guarantees that no duplicates are stored. Which two interfaces provide that capability? (Choose Two)
 
A. java.util.Map
B. java.util.Set
C. java.util.List
D. java.util.StoredSet
E. java.util.StoredMap
F. java.util.Collection
 
Answer:B,D
155.
 Which statement is true for the class java.util.ArrayList?
 
A. The elements in the collection are ordered.
B. The collection is guaranteed to be immutable(不可变的)
C. The elements in the collection are guaranteed to be unique.
D. The elements in the collection are accessed using a unique key.
E. The elements in the collections are guaranteed to be synchronized.
 
Answer : A
156. @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Given:
1. public class Foo {
2. private int val;
3. public foo(int v) (val = v;) }
4. public static void main (String [] args) {
5. Foo a = new Foo (10);
6. Foo b = new Foo (10);
7. Foo c = a;
8. int d = 10;
9. double e = 10.0;
10. }
11. }
 
Which three logical expressions evaluate to true? (Choose Three) 
A.(a ==c)
B.(d ==e)
C.(b ==d)
D.(a ==b)
E.(b ==c)
F.(d ==10.0)
 
Answer A,B,F
157.
Click the exhibit button:
 
1. public class Test {
2. public static void replaceJ(string text) {
3. text.replace (‘j’, ‘l’);
4. }
5.   
6. public static void main(String args[]) {
7. string text = new String (“java”)
8. replaceJ(text);
9. system.out.printIn(text);
10.     }
11. }   
 
What is the result?
A. The program prints “lava”.
B. The program prints “java”.
C. An error at line 7 causes compilation to fail.
D. Compilation succeeds but the program throws an exception.
 
Answer B
158.
What is the numerical range of a char?
A. 0 . . . 32767
B. 0 . . . 65535
C. -256 . . . 255
D. -32768 . . . 32767
E. range is platform dependent
 
Answer B
159.
Given:
1. public class Foo {
2.    public void main (String [] args)   {
3.      system.out.printIn(“Hello World.”);
4.     }
5. }
 
What is the result?
A.An exception is thrown.
B.The code does not compile.
C.“Hello World.” is printed to the terminal.
D.The program exits without printing anything.
 
Answer A
当main 方法错误定义时, 编译都能通过, 但运行时会出错.
160. @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
 Which type of event indicates a key pressed on a java.awt.Component?
A. KeyEvent
B. KeyDownEvent
C. KeyPressEvent
D. KeyTypedEvent
E. KeyPressedEvent
 
Answer A
161. @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
How can you create a listener class that receives events when the mouse is moved?
 
A.By extending MouseListener.
B.By implementing MouseListener.
C.By extending MouseMotionListener.
D.By implementing MouseMotionListener.
E.Either by extending MouseMotionListener or extending MouseListener.
F.Either by implementing MouseMotion Listener or implementing MouseListener.
 
Answer D
 
162. @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Which statement is true?
 
A. A grid bag layout can position components such that they span multiple rows and/or columns.
B. The “North” region of a border layout is the proper place to locate a menuBar component in a Frame.
C. Components in a grid bag layout may either resize with their cell, or remain centered in that cell at their preferred size.
D. A border layout can be used to position a component that should maintain a constant size even when the container is resized.
 
Answer A
 
163.
Given:
1. public class Test {
2. public static void main (String args[]) {
3.    class Foo {
4.      public int i = 3;
5.     }
6.     Object o = (Object) new Foo();
7.     Foo foo = (Foo)o;
8.     System.out.printIn(foo. i);
9.     }
10. }
 
What is the result?
A.Compilation will fail
B.Compilation will succeed and the program will print “3”
C.Compilation will succeed but the program will throw a ClassCastException at line 6 
D.Compilation will succeed but the program will throw a ClassCastException at line 7
 
Answer B
164
Which two create an instance of an array? (Choose Two)
 
A. int[] ia = new int [15];
B. float fa = new float [20];
C. char[] ca = “Some String”;
D. Object oa = new float[20];
E. Int ia [][] = (4, 5, 6) (1, 2, 3)
 
Answer A,D
 
165
 1. public class X {
 2.    public static void main(String [] args) {
 3.      Object o1= new Object();
 4.      Object o2= o1;
 5.      if(o1 .equals(o2)) {
 6.        System.out.println("Equal");
 7.      }
 8.    }
 9. }
What is the result?
 A. The program runs and prints nothing.
 B. The program runs and prints "Equal".
 C. An error at line 5 causes compilation to fail.
 D. The program runs but aborts with an exception.
 
 Answer :B
 
 

你可能感兴趣的:(compilation,class,string,exception,button,float)