大鹏终极总结JAVA(4)

switch里面只能是short,int,char,byte的.

if (a="a") 编译错, if(a=false)编译ok,原因是a=false的a代表了个boolean值

这种写法Outer.Inner i = new Outer().new Inner(); OK!

byte -128~127 ,-128是二进制的多少?????????????

-1>>32还是-1, -1>>>32为什么还是-1???????????????????

char c='c'; String s ="s"; s+=c;结果是 sc!!!


AWT
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
所有组件flowLayout会被压缩为它们的最小尺寸

如果只是add,而不写东南西北中,默认是中

applet,panel默认布局是flowlayout   frame,dialog默认布局是borderlayout

window,frame,dialog不能被嵌入到容器里.注意:window!

action event作用于button和textfeild的回车时刻

item event作用于list,choice,checkbox的选择改变时刻

gridLayout里的component尺寸一样

System.exit();在Applet里面不允许调用.


AWT事件
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
事件类有(symantic)语义事件:ActionEvent,AdjustEvent,ItemEvent,TextEvent
低级事件:ComponentEvent,ContainerEvent,FocusEvent,InputEvent,KeyEvent,MouseEvent,PaintEvent,WindowEvent

监听器:
ActionListener,AdjustListener,CompentListener,ContainerListener,FocusListener,ItemListener,
KeyListener,MouseListener,MouseMotionListener,TextListener,WindwosListener, 共11个Listener,
七个adpter,少的4个是ActionLisenter,AdjustListener,ItemListener,TextListener,它们只有一个方法.


鼠标MouseListener有5个方法:clicked,pressed,released,entered,exited

鼠标MouseMotionListener有2个方法:mouseDragged,mouseMoved


类和对象(Class and Object)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
最外层的类可以声明成final: "$file a":< final class a{}> ok!,但是不能是private和static的.

overload是同类里同样的方法名,override是父子的继承

override的返回结果必须一样,否则编译错

override的modifier可以扩大,但是不能缩小.比如父类private void test(){} 子类:public void test(){} ,没问题;如果反了,就不OK!

static和非static之间永远无法override!

看程序
public class A{
void test1() throws BaseEx{hi();}
void hi(){System.out.println("say hi,a");}
}
class AA extends A{
void hi(){System.out.println("say hi,aa");}
}
class test{
static void main(String b[]) throws Exception{
A a = new AA();
a.test1();
}
}
结果是,"say hi,aa",这说明什么?说明,方法永远跟着类的原来面目走;而,变量恰恰相反!

一个非抽象方法死活也别想override成一个抽象方法

override的子类的方法抛出的的异常只能是父类方法抛出异常的子异常类,或者无!

构造器不能是native,final,static,synchronized的,可以是public,private,什么都没有的。

构造器函数里还可以写return呢,但后面什么都不许有,甚至null

构造器不能返回值.这大家都知道,但如果有个"构造器"反值了,别紧张,它就不是构造器喽,只是个普通函数

super();this();这两个函数只能在构造函数里调用.

成员变量声明时候赋值,比构造函数还早.int i=1; ealier than Test(){}

方法的参数变量可以是final.

hashCode返回一个int

java.lang.Void 是void的包装类

Byte,Interger,Double...所有的跟数有关的包装类都是继承于Number


接口Interface)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
接口的所有方法默认都是public,abstract和non-static的

接口的所有变量默认都是public,static,final的.所以,接口的变量不能改值,在它的实现类里.

接口的实现类实现的方法必须和接口的方法抛出同样的异常,不许是子类,这和override不一样!同样,如果接口方法没有抛,实现方法也不能抛.

实现类实现的方法必须显式的声明成public,什么都不写都不行,啊!!!

一个类实现两个接口,如果两个接口有相同的方法,实现类就实现这个方法,没问题的.

内嵌类Inner Class)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
内嵌类可以访问outer类的任何变量,包括私有的.

静态inner类,只能访问outer类的任何static变量

内嵌类可以是final,abstract的

我靠,方法内的内嵌类不能为static: void test(){ static class A{}} XXXXX!!!!
我靠,方法内的内嵌类也不能带任何modifier,void test(){ public class A{}} XXXXX!!!!
我靠,方法内的内嵌类只能访问方法内的final变量,但是,可以访问outer类的任何变量.

匿名类不能有构造器,但声明时候带参数,相当于构造器的参数传递.
class ABC{}
class ABCD{private ABCD(int i){}}
ABC test3(){return new ABC(){};}
ABCD test4(){return new ABCD(3){};}
interface iii{}
iii test5(){return new iii(){};}
//class BCD extends ABCD{} compile error,因为,
看上面就知道,new iii(){};实际上匿名类实现了iii接口;new ABC(){};实际上是匿名类继承了ABC.
8.???
class A {private A(){System.out.println("a!");}}
class B extends A{}
我靠,没错!B实例的时候会主动调用父类A的构造,即使是private的,看来也没问题!!!
9.内部类可以有synchronized方法,那么锁是这个内部类,跟外部类没一点关系,内外分别的,在锁的问题上.
10.外部类不能通过this被访问,this这时候应该指的是内部类,享用外部类的成员就直接用,不用加任何限定词
11.如何用this呢?请看:
class Outer{ int i;
class Inner{
class InnerInner{
void Test(){
Outer.this.i=1;
}
}
}
}
看见了吧,类名.this.变量名,可以引用到i,第一次看到吧,嘿嘿,孤陋寡闻.
12.注意这两种写法都可以
Class Outer.Inner i = new Outer().new Inner();
或者, Class o= new Outer(); Class Outer.Inner i=o.new Inner();
线程Thread)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
?????去看Thread的API!!!!
1.线程启动必须通过start函数.
2.run函数不许也只能是public的.
3.线程有优先级从1到10,通过Thread.setPriority(int);来改变,不能超过10,否则会出现运行异常
4.线程优先级默认是5,即NORM_PRIORITY.????????NORM_PRIORITY是Thread的静态变量吗?
5.????Thread.yeild();是静态方法,所以,使用格式是Thread.yield();她强迫当前的进程放弃CUP.
6.sleep(1000),是说线程睡觉1秒,然后,进入Ready状态,注意,不是运行状态,它还要等OS来调度来获得CUP.

java.lang.*;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1.数组的科隆: int ia[][]={{1,2},null}; int ib[][]=(int[][])ia.clone();
2.什么是NaN?????然后看ceil(NaN),floor(NaN),...
3.Math.floor(-1.1f);//-2.0
Math.ceil(-1.1f);//-1.0
Math.round(-1.6d)//-2
4.0=<double random()<1
5.Math,Interger,Boolean...等类型包装类都是final的,不可继承
6.int round(float); long round(double);唉,round永远返回不了小数点
7.static double ceil(double)
8.static double floor(double)注意,ceil,floor的只有这个double版本,什么都转成double!
9.static double sin(double 弧度); 还有cos,tan
10. new String; ?可以是byte[];char[];String;StringBuffer
11. String的一些函数: int length(); char charAt(int); String toUpperCase(); String toLowerCase();
12. String("Abc").equals(String("abc"))不相等的,不然就不会有boolean equalsIgnoreCase(String)函数
13."012345678"是一个串的顺序号码,indexOf('1'),indexOf("1")都返回1,subString(1,5)是2345,嘿嘿:是"[)"的感觉
14, trim()连tab都退毛,"/t/n java ",trim()一下就只剩下"java"了
15. 关于对象的科隆,去喳喳API??????????????????????
16. "abcd".trim(),"abcd" + new String("ef")都是合理的写法
17. StringBuffer的3个构造器: ()初始化容量为16,(int 初始化容量),(String),初始化容量为串长加上16
18. StringBuffer的一些函数: String toString(); append();reverse();insert();delete(int start,int end);deleteCharAt(int);setLength(int newLength);
19. String s=""; StringBuffer sb=new StringBuffer(); if (s==sb){}编译错!因为,s,sb类型不一样,不能比较
集合:
1.各接口和类的关系,只有最后一个是类
Collection:List:vector,ArrayList,LinkedList
Map:SortedMap:TreeMap
Collection:Set:SortedSet:TreeSet
Map:HashTable
Collection:Set:HashSet
基础Base)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1.java application的main可以不是public的.但必须是static的
2.一个文件只能有一个public类,而且还得跟文件名一样,包括大小写
3.变量只能是字母,$,_开头,接下来的第二个可以是,数字
4.ch/u0061r='a'; char /u0063='b'; char c='/u0063';都是合法的
5.1e-5d,合法.e-5d不合法,必须有前面的系数
6.int[] i[]={null{1,2}}正确! int i[]={1,2,3,} 正确!","和没有的效果一样
7.局部array,跟变量一样,使用前要初始化
8.main方法可以为final
操作符和分配符(Operator and Assignment)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1.System.out.printl(1+2+"3");//33 System.out.printl("1"+2+3);//123
2.int i=0; i=i++;i=i++;i=i++; 结果,i=0!
3.int i[]; index=0; i[index]=index=5; 结果是,i[0]=5;!!!
4.byte b=10;可以,因为,10可以被自动从int转成byte
5.接下来,byte b=b+10;不可以!!因为,10+b后的int无法被自动从int转成byte,问我,我也不知道为什么!靠!
6.byte b1 = 4; byte b2 = 6; b1 = b1 + b2;错!编译错!b1 + b2后,必须强制转成byte,b1x1+b2);
7.XOR 一样的为0,不一样为1 1,1=0;0,0=0;1,0/0,1=1
8. x == Float.NaN编译错,应该是Float.IsNaN
9. x == Double.POSITIVE_INFINITY编译可以
10.-1是1111.... 1111,<<永远右补零,>>正补零,负补一,>>>恒补零
10.1 -1>>多少位都是-1 ; 1<<31变成了最小负数,1000....0000
11.最大正数是01111....1111
12.最小负数是1000....0000(-2147483648)
13. a instanceof b,b必须是类/接口,不能是实例
--------补充------------------------------
1. byte,short,char 都存在 var = -var;编译错误,因为,这时候的-var已经自动转成个int类型了
2. int/0会扔出ArithmeticException
double,float/0得INF或者-INF
0/0得NaN
3. int a-b-c;是不符合命名规则的变量名????编译会出错.
4. char a='/u0001';对! char b=/u0001;编译错!
5. boolean b1,b2,b3,b4,b5;
b1 = b2==b3;
b1 = b2<=b3 && b4==b5;
b1 = b2==b3==true
都是对的!靠!变态!
b1 = b2==b3==b4 XXXXXXX编译错!
6. 1>>1 是0
7. %= <<= =>> =>>>都是合法符号
8. --1-10*4 这种写法没错,就是 (--1)-10*4
9. k=1;++k + k++ + +k ;结果是7,相当于 (++2)+(2++)+(+3)
10.标号不能标示声明.
hi:
if {
break hi;
//break hi1;不行,不能向后调转
}
//hi1:不行,不能放在声明前
int i;
hi1:
i=1;
11.public static void main(String s[]) throws Exception{}可以噢,main可以扔出异常
12. hi:
if(b==true){break hi;}
break 标号,可以用在if里面.别的任何都不行,包括break,continue 标号.
13.int x = i*-j; 我靠,没问题的!!!编译没错! int x = i*j++ + +i++; 这个也没问题,
变量修饰符(Modifier)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1.最外面一层的类不能声明成protect和pravite的
2.同一个类的两个实例之间可以访问彼此的私有方法和私有变量,酷
3.protect和无修饰符的具体区别???????关于外包可以访问被子类访问的是哪个?
4.成员变量被修饰成final后,必须声明时候就赋初值或者在构造器里面赋初值,别指望她可以得到default值.
5.抽象方法不能是static的!!!
6.静态方法将随着类的变化而变化,看例子:
class Parent{
static void test(){System.out.println("hi,parent")};
}
class Child extends Parent{
static void test(){System.out.println("hi,child")};
}
Parent p = new Child();
p.test(); //打出来的是hi,parent!
7.静态方法可以通过类的实例调用.
new Child().test(); 和 Child.test(); 都OK!
8.transient只能用在类的成员变量上,不能用在方法里.
9.transient变量不能是final和static的
10.native方法可以是private,abstractd的
流程控制
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1。不可到达的语句声明为错:while(false){} ;for(;false{};if(false){}都无法编译
2。for(第一部分;的第一部分可以用来声明或者赋值,但不能两者都
3。byte b; switch  { case 200: // 200 not in range of byte,因为200超过b的范围,将编译错误
4。带标签的continue回达到标签的位置,从新进入紧接在标签后面的循环
5。带标签的break会中断当前循环,并转移到标签标示的的循环的末尾
转型和上溯(Converting and Casting)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Binary operators convert the smaller(less precise) operand to the type of the larger(more precise) operand.
All operators will convert things smaller than ints to ints or larger. This includes char 's!
1.byte,char,short默认转成int
2.byte->short->int->long->float->double
char^
这是默认可以转型的方向,反了必须要显式cast! 特别注意:long->float是默认的,别看long64,float32,嘿嘿
还有就是看得出来,char和 byte,short之间无法互相默认转换
3.float f=1/3; OK!float f=1.0/3.0;编译出错,因为1.0/3.0结果是double的,噢噢~,错喽!!
4.int i=1; byte b=i;错!需要显式cast.
final i=1; byte b=i;就ok! 我也不知道为什么,final就可以.而且,据我实验只有int和byte的关系这样,其他不行.
5.int i[]; Object[] obj=i;错! Object obj=i;对! 数组只能转成Object,而不能是Object[]
6.int i[]; Object[] obj;i=(int[])obj; 对! 对象可以通过显式来转成一个数组.

I/O
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1.File类的一些重要方法:isFile();isDirectory();String[] list();exists();getAbsolutePath();getParent();
2.通过delete();mkdir();rename(File newname);可以操纵文件,但是却改变不了文件的内容
2.1 File类无法改变当前目录,除非重新创建一个File对象.
3.InputStreamReader(InputStream in,String encodingName);
OutputStreamReader(OutputStream in,String encodingName);
Encoding: 8859_1是Latin-1,包含ASCII
4.关闭close一个流,就自动调用了flush.
5.System.in,System.out,System.err,由JVM自动创建
6.RandomAccessFile(File file,String mode);mode有,r,rw



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


3. public class IfTest{
 public static void main(String args[]){
        int x=3;
 int y=1;
 if(x=y)
 System.out.println("Not equal");
 else
 System.out.println("Equal");
 }
 }
 what is the result?
Answer:compile error
4. public class Foo{
  public static void main(String args[]){
  try{return;}
   finally{ System.out.println("Finally");}
   }
    }
 what is the result?
 A. print out nothing
 B. print out "Finally"
 C. compile error
Answer:B
5. public class Test{
  public static String output="";
   public static void foo(int i){
    try {
if(i==1){
throw new Exception();
}
output +="1";
 }
 catch(Exception e){
 output+="2";
 return;
 }
 finally{
 output+="3";
  }
 output+="4";
 }
 public static void main(String args[]){
 foo(0);
 foo(1);
 24)  
    }
    }
 what is the value of output at line 24?
Answer:13423
6. public class IfElse{
 public static void main(String args[]){
 if(odd(5))
 System.out.println("odd");
 else
 System.out.println("even");
 }
  public static int odd(int x){return x%2;}  
  }
  what is output?

Answer:Compile Error

7. class ExceptionTest{
  public static void main(String args[]){
  try{
methodA();
}
  catch(IOException e){
System.out.println("caught IOException");
  }
  catch(Exception e){
  System.out.println("caught Exception");
   }
  }
  }
 If methodA() throws a IOException, what is the result?
Answer:caught IOException
exception can catch once only
if change the sequence of catch
  catch(IOException e) can't execute  and compiler will report rongyu error

8. int i=1,j=10;
 do{
 if(i++>--j) continue;
 }while(i<5);
After Execution, what are the value for i and j?
A. i=6 j=5
B. B.i=5 j=5
C. i=6 j=4
D. i=5 j=6
E. i=6 j=6
Answer:D

9. 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;
 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

10.    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?
Answer:compile successed and i=0
11. what is reserved words in java?
  A. run
  B. default
  C. implement
  D. import
Answer:B,D
12. public class Test{
   public static void main(String[] args){
   String foo=args[1];
   Sring bar=args[2];
   String baz=args[3];
    }
    }
   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
13. 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
14. 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
15. public class Foo{
   public static void main(String args[]){
   String s;
   System.out.println("s="+s);
    }
   }
   what is the result?
Answer:compile error
16.   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
17. 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,E
18.  public class Test{
   public static void add3(Integer i){
 3) int val=i.intvalue();
    val+=3;
    i=new Integer(val);
    }
    public static void main(String args[]){
     Integer i=new Integer(0);
        add3(i);
     System.out.println(i.intvalue());
     }
       }
    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
19. public class Test{
    public static void main(String[] args){
     System.out.println(6^3);
     }
       }
   what is output?
Answer:5    
^ is yi huo
20. public class Test{
   public static void stringReplace(String text){
     text=text.replace('j','l');
    }
    public static void bufferReplace(StringBuffer text){
      text=text.append("c");
     }
   public static void main(String args[]){  
     String textString=new String("java");
     StringBuffer textBuffer=new StringBuffer("java");
      StringReplace(textString);
      bufferReplace(textBuffer);
    System.out.println(textString+textBuffer);
      }
      }
   what is the output?
Answer:javajavac
21. public class ConstOver{
   public ConstOver(int x, int y, int z){}
    }
   which two overload the ConstOver constructor?
   A.ConstOver(){}
   B.protected int ConstOver(){}   //not overload ,but no a error
   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
22. public class MethodOver{
    public void setVar(int a, int b, float c){}
    }
   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
23. class EnclosingOne{
  public class InsideOne{}
    }
  public class InnerTest{
   public static void main(String args[]){
   EnclosingOne eo=new EnclosingOne();
   //insert code here
   }
  }
  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
24. 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;}  
  D.interface A{}
interface B{}
interface C implements A,B{}   //syntex error
Answer:B
keyword implements,entends
25. 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:B
if out of outerclass A is correct
26. 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
27. 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
28. 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.compile error at line 6
  B.the program prints pairs of values for x and y that are
    always the same on the same time
Answer:B
29. 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
30. Given an ActionEvent, how to indentify the affected component?
    A.getTarget();
    B.getClass();
    C.getSource();   //public object
    D.getActionCommand();
Answer:C
31. 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
32. 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
33. How to calculate cosine 42 degree?
  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.toRadious(42);
Answer:C
34. public class Test{
   public static void main(String[] args){
   StringBuffer a=new StringBuffer("A");
   StringBuffer b=new StringBuffer("B");
   operate(a,b);
   System.out.pintln(a+","+b);
    }
   public static void operate(StringBuffer x, StringBuffer y){
    x.append(y);
    y=x;
   }
   }
   what is the output?
Answer:A,B
35.  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;
   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
36. 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
37. 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) has exit

38. 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
39. 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
40. 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)
Answer:A
41. 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
42. 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
43. which two are equivalent?
  A.  3/2
  B.  3<2
  C.  3*4
  D.  3<<2
  E.  3*2^2
  F.  3<<<2
Answer:C,D
44. int index=1;
  String[] test=new String[3];
  String foo=test[index];
  what is the result of foo?
   A. ""   B.null    C.throw a Exception   D.not compile
Answer:B
45. 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?
Answer:4
46. 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
47. public class Test{
   private static int j=0;
   public static boolean methodB(int k){
     j+=k;
    return true;
   }
   public static void methodA(int i){
    boolean b;
    b=i>10&methodB(1);
    b=i>10&&methodB(2);
     }
    public static void main(String args){
     methodA(0);
  17)
     }
     }
   what is the value of j at line 17?
Answer:1
48. 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
49. 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
50.  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
51. public class Test{
   public static void main(String[] args){
   String foo="blue";
   String bar=foo;
   foo="green";
   System.out.println(bar);
   }
   }
   what is the result?
Answer:blue
52. which interface Hashtable implements?
  A. java.util.Map
  B. java.util.List
  C. java.util.Hashable
  D. java.util.Collection
Answer:A
53. 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
54. 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
55. 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
56.  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,E
57. 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
58. 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:A,D
59. which two are true?
  public class OuterClass{
   private double d1=1.0;
   //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
60. 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
61. which two statements declare an array capable of 10 ints?
  A. int[] foo;
  B. int foo[];
  C. int foo[10];
  D. Object[] foo;
  E. Object foo[10];
Answer:A,B
62. 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
63. 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
64. 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
65. 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
66. 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);
        }
       }
    }    
  which codes are added to line 3 to cause run() to be executed?
  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:C(A) because run is not static
67. 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
68. 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
69.  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
public class sub extends super{
public sub(string text){
super(), this must be the first line.
};
70.   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
71.   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
72.  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
73. 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
74. 1)public class Foo implements Runnable{
  2)  public void run(Thread t){
     System.out.println("Running");
      }
    public static void main(String[] args){
     new Thread(new Foo()).start();
     }
     }
   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:D
75. 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
76. 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
77. 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
78.   public class X{
    public Object m(){
  3)Object o=new Float(3.14f);
    Object[] oa=new Object[1];
    Oa[0]=0;
    o=null;
    return oa[0];
    }
    }
   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:D
79. which will declare a method that forces a subclass to implement?
  A.public double methoda()
  B.abstract public void methoda()
Answer:B    
80. //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
81. 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
82.  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) }
    A:what is the result?
    B:compile fail on line 6
Answer:B
83. 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
Answer:A
84. 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
85. 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
86. which statement is true for the class java.util.HashSet?
  A.The elements in the collection are ordered
  B.The collection is guaranteeded to be immutable
  C.The elements in the collection are guaranteeded 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
87.  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:B,D,F
88. 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?
Answer:Cimpile error
89. 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
90. public class Foo{
    public static void main(String[] args){
     int i=1;
     int j=i++;
     if((i>++j)&&(i++==j)){
         i+=j;
         }
         }
        }
   what is the final value i and j?
Answer:i=2,j=2    
91. which two are equivalent?
  A.16>4
  B.16/2
  C.16*4
  D.16>>2
  E.16/2^2
  F.16>>>2
Answer:D,F
92. public class X{
    public static void main(String[] args){
     byte b=127;
  4) byte c=126;
  5) byte d=b+c;
    }
    }
  A.Line 5 throws an exception indicating "out of range"
  B.Line 5 cause a compile fail
  C.compile succeeded
Answer:B
93. 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 create 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
94. which two create an InputStream and open the file"file.txt"
  for reading?
  A.InputStream in=new FileInputStream("file.txt");
  B.FileInputStream in=new FileInputStream(new File("file.txt"));
  C.InputStream in=new FileReader("file.txt");
Answer:A,B
95. which constructs a BufferedInputStream?
  A.new BufferedInputStream(new FileInputStream("in.txt"));
  B.new BufferedInputStream(new FileReader("in.txt"));
Answer:A
//FileReader is a char stream
96. which can be used to encode chars for output?
  A.java.io.OutputStreamWriter
  B.java.io.FileOutputStream
  C.java.io.DataOutputStream
Answer:A
97. which determines if "prefs" is a directory and exist on the file system?
  A.boolean exists=(new File("prefs")).isDirectory();
  B.boolean exists=(new File("prefs")).isDir();
Answer:A
98.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
99. import java.awt.*;
   public class Test extends Frame{
    public Test(){
      add(new Label("Hello"));
      add(new TextField("Hello"));
      add(new Button("Hello"));
      pack();   //BorderLayout  --the four area around will be lost
     show();}
   public static void main(String[] args){
    new Test();
    }
    }
  what is the result?  
Answer:center is only a button"hello"and has a window "Test"
100. which is true?
     A. Any statement that may throw an Exception must be enclosed in a try block.
//Standard Exception (Runtime Exception) is not
     B. Any statement that may throw an Error must be enclosed in a try block.
     C. Any statement that may throw an RuntimeException must be enclosed in a try block.
     D.No exception are subclass of Error.
Answer:D
101. which one 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 not 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:C
102.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:D
103.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?
Answer:0.0
104.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

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值