大鹏终极总结JAVA之SCJP攻略版

 (1) Main method calling a non-static method. (illegal)
   在main(String[] args)方法内调用一个非静态方法。(非法)


(2) Methods with the same name as the constructor(s). (这种题常有)
   与Constructor(s)有相同名字的方法。 Constructor不是关键字
另:
class A{
A(){ //是构造函数 }
void A(){ //不是构造函数,只是个普通函数(方法) }
}

 

(3) Local inner classes trying to access non-final vars. (illegal)
   内部类尝试访问非final变量(非法)

 

(4) instanceOf is not same as instanceof.
   instanceOf 不是 instanceof。

 

(5) Private constructors. (legal)
   私有 的Constructor。 (合法)

 


(6) System.exit() in try-catch-finally blocks. (finally 不会执行)
    System.exit()在try-catch-final块中的退出语句。 (finally不会执行)
    另:有return语句的时候finally在return前执行

 

(7) main() can be declared final. (OK)
    main()方法 可以声明为 final.

(8) -0.0 == 0.0 is true.
   

(9) A class without abstract methods can still be declared abstract
    没有 抽象方法的类,仍然可以定义为抽象类。

 

(10) Map does not implement Collection.
    Map 并不实现 Collection.


(11) Dictionary is a class, not an interface.
    Dictionary 是一个类,不是接口。


(12) Collection is an Interface where as Collections is a helper class. (这题我倒没见过,但还真容易看混)
    Collection是一个接口,但 Collections却是一个辅助类。

 

(13) Class declarations can come in any order.
     (也就是说: class Child extends Parents{}
                class Parents{}
      这种顺序是可以的.)
    可以以任何顺序申明类。

 

(14) Strings are initialized to null, not empty string.
    String 是被初始化为 null,不是空字符。

 


(15) "continue" must be in a loop(for, do, while). It cannot appear in case constructs.
    “continue”已经要在一个循环里(如for,do,while),它不能在case语句中出现。


(16) A constructor can throw any exception.
    一个Constructor可以抛出任何异常。


(17) All comparisons involving NaN and a non-Nan would always result false. (对大多数朋友来说这可是个盲点噢)
    所有关于 NaN(Not a Number) 和 non-NaN 的比较,都返回false.
    这条很重要。

 

(18) integer (and long ) operations / and % can throw ArithmeticException while float / and % will never, even in case of division by zero.
    integer和long 操作 /和% 的话, 会抛出ArithmeticException,
     但是 float形不会,即使是除以0。

 

(19) == gives compiler error if the operands are cast-incompatible.
    ==会产生编译错误,如果两边 不兼容的话。


(20) You can never cast objects of sibling classes( sharing the same parent ), even with an explicit cast.
     你永远不可能 转化具有同一个超类的类的对象,即使是刻意转化。(请提意见)

例:
class A
class sonA extends A
class daughterA extens A
对这种情况:
sonA 和 daughterA 之间不能相互转化。
即:sonA son = (sonA) daughterA();是非法的。
而:sonA son = (sonA) A();是合法的。
A father = (A) sonA()和A father =sonA()也是合法的


(21) .equals returns false if the object types are different.It does not raise a compiler error.
    equals() 返回 false 如果对象类型不同,但不产生 编译错误。


(22) File class has NO methods to deal with the contents of the file.(also the existing directory)
    File类没有 任何 处理文件内容的方法。(当然,存在的目录也一样)
 
(23) InputStream and OutputStream are abstract classes, while DataInput and DataOutput are interfaces.
    InputStream 和 OutputStream 是 抽象类,
     但是 DataInput 和 DataOutput是 接口。


(24)if 和while后面的表达式结果只能是逻辑型的
如if(1),while(0)都是非法的

 

1 什么是Java、Java2、JDK?JDK后面的1.3、1.4.2版本号又是怎么回事?
答:Java是一种通用的,并发的,强类型的,面向对象的编程语言(摘自Java规范第二版) JDK是Sun公司分发的免费Java开发工具,正式名称为J2SDK(Java2 Softw
are Develop Kit)。

2 什么是JRE/J2RE?
答:J2RE是Java2 Runtime Environment,即Java运行环境,有时简称JRE。
如果你只需要运行Java程序或Applet,下载并安装它即可。
如果你要自行开发Java软件,请下载JDK。在JDK中附带有J2RE。
注意由于Microsoft对Java的支持不完全,请不要使用IE自带的虚拟机来运行Applet,务必安装一个J2RE或JDK。

3 学习Java用什么工具比较好?
答:作者建议首先使用JDK+文本编辑器,这有助你理解下列几个基础概念:path,class
path,package并熟悉基本命令:javac和java。并且下载和你的JDK版本一致的API帮助。

如果你不确定类或函数的用法,请先查阅API而不是发贴求助。
当你熟悉Java之后,你可以考虑换一个IDE。很多人推荐JCreator,实际上JCreator的功能还 是很弱的。
作者推荐eclipse,下载网址http://www.eclipse.org ;。因eclispe是免费的.

4 学习Java有哪些好的参考书?
答:作者首先推荐Thinking in Java,中文名《Java编程思想》,有中文版。
该书第一章介绍了很多面向对象的编程思想,作为新手应当认真阅读。
除此以外,O′relly出版社和Wrox出版社的书也不错。作者本人不喜欢大陆作者的书。
也许你觉得英文太难,但是网上大多数资料都是英文的。另外,你需要经常查阅API,而那也是英文的。

5 Java和C++哪个更好?
答:这个问题是一个很不恰当的问题。你应该问:Java和C++哪个更适用于我的项目?
如果你不需要跨平台,不需要分布式,要强调程序的运行速度,C++更为适用。
反之?你应当考虑Java。

6 什么是J2SE/J2EE/J2ME
答:J2SE就是一般的Java。
J2ME是针对嵌入式设备的,比如Java手机,它有自己的SDK。而J2EE使用J2SE的SDK。
J2EE规范更多的是对J2EE服务器的要求和开发人员的约束。详情见后继《J2EE FAQ》。

二、命令篇
7 我写了第一个Java程序,应该如何编译/运行?
答:首先请将程序保存为xxx.java文件,
然后在dos窗口下使用javac xxx.java命令,你会发现该目录下多了一个xxx.class文件,再使用java xxx命令,你的java程序就开始运行了。

8 package是什么意思?怎么用?
答:为了唯一标识每个类并分组,java使用了package的概念。
每个类都有一个全名,例如String的全名是java.lang.String,其中java.lang是包名,String是短名。
这样,如果你也定义了String,你可以把它放在mypackage中,通过使用全名mypackage.String和java.lang.String来区分这两个类。同时,将逻辑上相关的类放在同一个包中,可以使程序结构更为清楚。
你要做的就是在java文件开头加一行"package mypackage;"。
注意包没有嵌套或包含关系,A包和A.B包对java命令来说是并列的两个包(虽然开发者
可能?

9 在一个类中怎么使用其他类?
答:如果你使用java.lang包中的类,不用做任何事。
如果你使用其他包中的类,使用import package1.class1; 或 import package2.*;
这里.*表示引入这个包中的所有类。然后在程序中你可以使用其他类的短名。
如果短名有冲突,使用全名来区分。

10 我想把java编译成exe文件,该怎么做?
答:JDK只能将java源文件编译为class文件。
class文件是一种跨平台的字节码,必须依赖平台相关的JRE来运行。Java以此来实现跨平台?有些开发工具可以将java文件编译为exe文件。作者反对这种做法,因为这样就取消了跨平台性。


三、I/O篇

18 我怎么给java程序加启动参数,就像dir /p/w那样?
答:还记得public static void main(String[] args)吗?这里的args就是你的启动参
数。
在运行时你输入java package1.class1 -arg1 -arg2,args中就会有两个String,一个
是arg
1,另一个是arg2。

19 我怎么从键盘输入一个int/double/字符串?


答:java的I/O操作比C++要复杂一点。如果要从键盘输入,样例代码如下:
BufferedReader cin = new BufferedReader( new InputStreamReader( System.in ) )
;
String s = cin.readLine();
这样你就获得了一个字符串,如果你需要数字的话再加上:
int n = Integer.parseInt( s ); 或者 double d = Double.parseDouble( s );

20 我怎么输出一个int/double/字符串?
答:在程序开始写:
PrintWriter cout = new PrintWriter( System.out );
需要时写:
cout.print(n); 或者cout.println("hello")等等。

21 我发现有些书上直接用System.in和System.out输入输出,比你要简单得多。
答:java使用unicode,是双字节。而System.in和System.out是单字节的stream。
如果你要输入输出双字节文字比如中文,请使用作者的做法。

22 我怎么从文件输入一个int/double/字符串?
答:类似于从键盘输入,只不过换成
BufferedReader fin = new BufferedReader( new FileReader(" myFileName " ) );
PrintWriter fout = new PrintWriter( new FileWriter(" myFileName " ) );
另外如果你还没下载API,请开始下载并阅读java.io包中的内容。

 

23 我想读写文件的指定位置,该怎么办?
答:你肯定没有认真看API。java.io.RandomAccessFile可以满足你的需要。

24 怎么判断要读的文件已经到了尽头?
答:你肯定没有认真看API。在Reaer的read方法中明确说明返回-1表示流的结尾。

四、 关键字篇

25 java里面怎么定义宏?
答:java不支持宏,因为宏代换不能保证类型安全。
如果你需要定义常量,可以将它定义为某个类的static final成员。参见26和30。

26 java里面没法用const。
答:你可以用final关键字。例如 final int m = 9。被声明为final的变量不能被再次
赋值?br> ?br> final也可以用于声明方法或类,被声明为final的方法或类不能被继承

注意const是java的保留字以备扩充。

27 java里面也不能用goto。
答:甚至在面向过程的语言中你也可以完全不用goto。请检查你的程序流程是否合理。
如果你需要从多层循环中迅速跳出,java增强了(和C++相比)break和continue的功能
,支?br> ?label。


例如:
outer :
while( ... )
{
inner :
for( ... )
{
... break inner; ...
... continue outer; ...
}
}
和const一样,goto也是java的保留字以备扩充。

28 java里面能不能重载操作符?
答:不能。String的+号是唯一一个内置的重载操作符。你可以通过定义接口和方法来实
现类
似功能。

29 我new了一个对象,但是没法delete掉它。
答:java有自动内存回收机制,即所谓Garbarge Collector。你再也不用担心指针错误
,内?br> 嬉绯隽恕?br>
30 我想知道为什么main方法必须被声明为public static?


答:声明为public是为了这个方法可以被外部调用,详情见面向对象篇37。
static是为了将某个成员变量/方法关联到类(class)而非实例(instance)。
你不需要创建一个对象就可以直接使用这个类的static成员,
在A类中调用B类的static成员可以使用B.staticMember的写法。
注意一个类的static成员变量是唯一的,被所有该类对象所共享的。

31 throw和throws有什么不同?
答:throws用于声明一个方法会抛出哪些异常。而throw是在方法体中实际执行抛出异常
的动
作。
如果你在方法中throw一个异常,却没有在方法声明中声明之,编译器会报错。
注意Error和RuntimeException的子类是例外,无需特别声明。

32 什么是异常?
答:异常最早在Ada语言中引入,用于在程序中动态处理错误并恢复。
你可以在方法中拦截底层异常并处理之,也可以抛给更高层的模块去处理。
你也可以抛出自己的异常指示发生了某些不正常情况。常见的拦截处理代码如下:
try
{
...... //以下是可能发生异常的代码
...... //异常被抛出,执行流程中断并转向拦截代码。
......
}


catch(Exception1 e) //如果Exception1是Exception2的子类并要做特别处理,应排在
前面
{
//发生Exception1时被该段拦截
}
catch(Exception2 e)
{
//发生Exception2时被该段拦截
}
finally //这是可选的
{
//无论异常是否发生,均执行此段代码
}

33 final和finally有什么不同?
答:final请见26。finally用于异常机制,参见32。

五、 面向对象篇

34 extends和implements有什么不同?
答:extends用于(单)继承一个类(class),而implements用于实现一个接口(inter
face
)。
interface的引入是为了部分地提供多继承的功能。


在interface中只需声明方法头,而将方法体留给实现的class来做。
这些实现的class的实例完全可以当作interface的实例来对待。
有趣的是在interface之间也可以声明为extends(单继承)的关系。

35 java怎么实现多继承?
答:java不支持显式的多继承。
因为在显式多继承的语言例如c++中,会出现子类被迫声明祖先虚基类构造函数的问题,

而这是违反面向对象的封装性原则的。
java提供了interface和implements关键字来部分地实现多继承。参见34。

36 abstract是什么?
答:被声明为abstract的方法无需给出方法体,留给子类来实现。
而如果一个类中有abstract方法,那么这个类也必须声明为abstract。
被声明为abstract的类无法实例化,尽管它可以定义构造方法供子类使用。

37 public,protected,private有什么不同?
答:这些关键字用于声明类和成员的可见性。
public成员可以被任何类访问,
protected成员限于自己和子类访问,
private成员限于自己访问。
Java还提供了第四种的默认可见性,当没有任何public,protected,private修饰时,成
员是?br> ?一包内可见??br>

类可以用public或默认来修饰。

38 Override和Overload有什么不同?
答:Override是指父类和子类之间方法的继承关系,这些方法有着相同的名称和参数类
型。
Overload是指同一个类中不同方法(可以在子类也可以在父类中定义)间的关系,
这些方法有着相同的名称和不同的参数类型。

39 我继承了一个方法,但现在我想调用在父类中定义的方法。
答:用super.xxx()可以在子类中调用父类方法。

40 我想在子类的构造方法中调用父类的构造方法,该怎么办?
答:在子类构造方法的第一行调用super(...)即可。

41 我在同一个类中定义了好几个构造方法并且想在一个构造方法中调用另一个。
答:在构造方法第一行调用this(...)。

42 我没有定义构造方法会怎么样?
答:自动获得一个无参数的构造方法。

43 我调用无参数的构造方法失败了。
答:如果你至少定义了一个构造方法,就不再有自动提供的无参数的构造方法了。
你需要显式定义一个无参数的构造方法。

 

44 我该怎么定义类似于C++中的析构方法(destructor)?
答:提供一个void finalize()方法。在Garbarge Collector回收该对象时会调用该方法

注意实际上你很难判断一个对象会在什么时候被回收。作者从未感到需要提供该方法。

45 我想将一个父类对象转换成一个子类对象该怎么做?
答:强制类型转换。如
public void meth(A a)
{
B b = (B)a;
}
如果a实际上并不是B的实例,会抛出ClassCastException。所以请确保a确实是B的实例

46 其实我不确定a是不是B的实例,能不能分情况处理?
答:可以使用instanceof操作符。例如
if( a instanceof B )
{
B b = (B)a;
}
else
{
...


}

47 我在方法里修改了一个对象的值,但是退出方法后我发现这个对象的值没变!
答:很可能你把传入参数重赋了一个新对象,例如下列代码就会造成这种错误:
public void fun1(A a) //a是局部参数,指向了一个外在对象。
{
a = new A(); //a指向了一个新对象,和外在对象脱钩了。如果你要让a作为传
出变
量,不要写这一句。
a.setAttr(attr);//修改了新对象的值,外在对象没有被修改。
}
基本类型也会出现这种情况。例如:
public void fun2(int a)
{
a = 10;//只作用于本方法,外面的变量不会变化。
}

六、java.util篇

48 java能动态分配数组吗?
答:可以。例如int n = 3; Language[] myLanguages = new Language[n];

49 我怎么知道数组的长度?


答:用length属性。如上例中的 myLanguages.length 就为 3。

50 我还想让数组的长度能自动改变,能够增加/删除元素。
答:用顺序表--java.util.List接口。
你可以选择用ArrayList或是LinkedList,前者是数组实现,后者是链表实现。
例如: List list = new ArrayList(); 或是 List list = new LinkedList(); 。

51 什么是链表?为什么要有两种实现?
答:请补习数据结构。

52 我想用队列/栈。
答:用java.util.LinkedList。

53 我希望不要有重复的元素。
答:用集合--java.util.Set接口。例如:Set set = new HashSet()。

54 我想遍历集合/Map。
答:用java.util.Iterator。参见API。

55 我还要能够排序。
答:用java.util.TreeSet。例如:Set set = new TreeSet()。放进去的元素会自动排
序。
你需要为元素实现Comparable接口,还可能需要提供equals()方法,compareTo()方法,
hash


Code()方法。

56 但是我想给数组排序。
答:java.util.Arrays类包含了sort等实用方法。

57 我想按不同方法排序。
答:为每种方法定义一个实现了接口Comparator的类并和Arrays综合运用。

58 Map有什么用?
答:存储key-value的关键字-值对,你可以通过关键字来快速存取相应的值。

59 set方法没问题,但是get方法返回的是Object。
答:强制类型转换成你需要的类型。参见45。


 1. Given:
1. public class test (
2.   public static void main (String args[])    {
3.       int  i = 0xFFFFFFF1;
4.       int  j = ~i;
5.  
6.      }
7. )
What is the decimal value of j at line 5?
A. 0
B. 1
C. 14
D. -15
E. An error at line 3 causes compilation to fail.
F. An error at line 4 causes compilation to fail.

2. 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))

3. Click the exhibit button:
1. public class test (    
2.          private static int j = 0;
3.        
4.        private 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 (4);
12.          b = i < 10 || methodB (8);
13. )
14.
15.  public static void main (String args[] }   (
16.              methodA (0);
17.              system.out.printIn(j);
18.            )
19. )
What is the result?
A. The program prints “0”
B. The program prints “4”
C. The program prints “8”
D. The program prints “12”
E. The code does not complete

4. Given:
1.Public class test (
2.    Public static void main (String args[])  (
3.     System.out.printIn (6 ^ 3);
4.   )
5.)
What is the output?
Ans:

5. Given:
1. public class Foo {
2.   public static void main (String [] args)  {
3.      StringBuffer a = new StringBuffer (“A”);
4.      StringBuffer b = new StringBuffer (“B”);
5.     operate (a,b);
6.     system.out.printIn{a + “,” +b};
7. )
8. static void operate (StringBuffer x, StringBuffer y)  {
9.           x.append {y};
10.           y = x;
11.     )
12. }
What is the result?
A. The code compiles and prints “A,B”.
B. The code compiles and prints “A,A”.
C. The code compiles and prints “B,B”.
D. The code compiles and prints “AB,B”.
E. The code compiles and prints “AB,AB”.
F. The code does not compile because “+” cannot be overloaded
for StringBuffer.

6. Click the exhibit button:
1. Public class test (
2. Public static void stringReplace (String text)  (
3.      Text = text.replace (‘j’ , ‘i’);
4. )
5.  
6. public static void bufferReplace (StringBuffer text)  (
7.     text = text.append (“C”)
8. )
9.  
10. public static void main (String args[]}  (
11.    String textString = new String (“java”);
12.    StringBuffer text BufferString = new StringBuffer
(“java”);
13.  
14.     stringReplace (textString);
15.     BufferReplace (textBuffer);
16.  
17.     System.out.printIn (textString + textBuffer);
18.     }
19.  )
What is the output?
Ans:

7. Click the Exhibit button:
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.  
8.   public static void main (String args [ ] )  {
9.    Integer  i = new Integer (0);
10.     add3 (i);
11.      system.out.printIn (i.intvalue ( )  );
12.   }
13. )
What is the result?
A. Compilation will fail.
B. The program prints “0”.
C. The program prints “3”.
D. Compilation will succeed but an exception will be thrown at
line 3.

8. Given:
1. public class ConstOver {
2.   public ConstOver (int x, int y, int z)  {
3.      }
4. }
Which two overload the ConstOver constructor? (Choose Two)
A. ConstOver ( ) { }
B. Protected int ConstOver ( ) { }
C. Private ConstOver (int z, int y, byte x) { }
D. public Object ConstOver (int x, int y, int z) { }
E. public void ConstOver (byte x, byte y, byte z) { }

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

10. 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;}

11. 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;
)

12. 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 multiple 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 enclosing outer class.

13. 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()”

14. Click the exhibit button:
1. public class enclosingone ( 2. public class insideone{} 3.
) 4. public class inertest( 5. public static void main
(string[]args)( 6. enclosingone eo= new enclosingone (); 7.
//insert code here 8. ) 9. )
Which statement at line 7 constructs an instance of the inner
class?
A. InsideOnew ei= eo.new InsideOn();
B. Eo.InsideOne ei = eo.new InsideOne();
C. InsideOne ei = EnclosingOne.new InsideOne();
D. EnclosingOne.InsideOne ei = eo.new InsideOne();

15. Click the exhibit button:

1. interface foo { 2. int k = 0; 3. ] 4.   5. public class
test implements Foo ( 6. public static void main(String
args[]) ( 7. int i; 8. Test test = new test (); 9. i= test.k;
10. i= Test.k; 11. i= Foo.k; 12. ) 13. ) 14.      
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.

16.  Given:
1. //point X
2. public class foo (
3. public static void main (String[]args) throws Exception {
4. printWriter out = new PrintWriter (new
5. 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.PrintWriter;
B. include java.io.PrintWriter;
C. import java.io.OutputStreamWriter;
D. include java.io.OutputStreamWriter;
E. no statement is needed.

17. Which two statements are reserved words in Java? (Choose
Two)

A. run
B. import
C. default
D. implement

18. Which three are valid declarations of a float? (Choose
Three)
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;

19. 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

20. Given:
1. public class test(
2. public static void main(string[]args){
3. 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

21. Given:
8. int index = 1;
9. int [] foo = new int [3];
10. int bar = foo [index];
11. int baz = bar + index;
What is the result?
A. baz has the value of 0
B. baz has the value of 1
C. baz has the value of 2
D. an exception is thrown
E. the code will not compile

22. Given:
1. public class foo {
2. public static void main (String[]args) {
3. String s;
4. system.out.printIn (“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.

23. 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){}

24. 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

25. 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.

26. 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”.

27. Given:
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) {retrun 4.0f; }

28. Which declaration prevents creating a subclass of an outer
class?
A. static class FooBar{}
B. private class FooBar{}
C. abstract public class FooBar{}
D. final public class FooBar{}
E. final abstract class FooBar{}

29. Given:
1. byte [] arry1, array2[];
2. byte array3 [][];
3. byte[][] array4;
If each array has been initialized, which statement will cause
a compiler 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

30. Click the exhibit button:
1. class super ( 2. public int I = 0; 3.   4. public super
(string text) ( 5. I = 1 6. ) 7.   ) 8.     9. public class
sub extends super ( 10. public sub (string text)   ( 11. i= 2
12. ) 13.   14. public static void main (straing args[])   (
15. sub sub = new sub (“Hello”); 16. system.out.
PrintIn(sub.i); 17.     )   18. )
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”.

31. 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

32. Given the ActionEvent, which method allows you to identify
the affected component?
A. getClass
B. getTarget
C. getSource
D. getComponent
E. getTargetComponent

33. 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)

34. 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.

35. You are assigned the task of building a panel containing a
TextArea at the top, a label directly below it, and a button
directly below the label. If the three components are 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

36. Which of the following gets the name of the parent
directory 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. Directory dir=(new File (“file.txt”)).getParentDir();
String name= dir.getName();

37. 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
  
38. 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.

39. 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 FileWriter(“out.txt”));
E. new dataOutputStream(new OutputStream(“out.txt”));
F. new dataOutputStream(new FileOutputStream(“out.txt”));

40. 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”);

41. Given:
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. return oa[0];
8. }
9. }
When is the float object created in line 3, eligible for
garbage collection?
A. Just after line 5
B. Just after line 6
C. Just after line 7 (that is, as the method returns)
D. Never in this method

42. Given:
3. string foo = “ABCDE”;
4. foo.substring(3);
5. foo.concat(“XYZ”);
6.  
Type the value of foo at line 6.
Ans:

43. 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));

44. You need to store elements in a collection that guarantees
that no duplicates are stored and all elements can be accessed
in natural order. Which interface provides that capability?
A. java.util.Map
B. java.util.Set
C. java.util.List
D. java.util.StoredSet
E. java.util.StoredMap
F. java.util.Collection

45. 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 accessed using a unique
key.
E. The elements in the collections are guaranteed to be
synchronized.

46. 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.

47. Click the exhibit button:
1. public class test ( 2. public static void main(string
args[]) { 3. int 1= 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

48. Given:
3. int i= 1, j= 10 ;
4. do (
5.  if (i++> --j) continue;
6. ) while (i<5);
After execution, what are the values for I and j?
A. i = 6 and j= 5
B. i = 5 and j= 5
C. i = 6 and j= 4
D. i = 5 and j= 6
E. i = 6 and j= 6

49. 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

50. Given:
1. public class foo {
2. public static void main (string[]args)
3. try {return;}
4. finally {system.out.printIn(“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.

51. Click the exhibit button.
1. import java.io.IOException; 2. public class ExceptionTest(
3. public static void main (String[]args) 4. try ( 5.
methodA(); 6. ) catch (IOException e)  ( 7.
system.out.printIn(“Caught IOException”); 8. ) catch
(Exception e)   ( 9. system.out.printIn(“Caught Exception”);
10.    ) 11. ) 12. public void methodA ()   { 13. throw new
IOException (); 14.     ) 15. )
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.

52. Click the exhibit button:
1. public class test { 2. public static string output = “” 3.  
 4. public static void foo(int i) { 5. try { 6. if(i= =1) { 7.
throw new Exception (); 8. } 9. output += “1”; 10. ) 11.
catch(Exception e)  { 12. output += “2”; 13. return; 14. ) 15.
finally ( 16. output += “3”; 17. ) 18. output += “4”; 19. )
20.   21. public static void main (string args[])  ( 22.
foo(0); 23. foo(1); 24.   25.     ) 26. )
What is the value of the variable output at line 24?
Ans:

53. Given:

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 exists without printing anything
C. An error at line 1 causes compilation to fail.
D. An error at line 2 causes the compilation to fail.    
E. “Running” is printed and the program exits

54. Which statement is true?
A. If only one thread is blocked in the wait method of an
object, and another thread executes the modify on that same
object, then the first thread immediately resumes execution.
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 first thread that executed the wait call
first definitely resumes execution as a direct and sole
consequence of the notify call.

55. Which two CANNOT directly cause a thread to stop
executing? (Choose Two)
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

56. 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.

57. 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.

58. Click the exhibit button:
1. class A implements runable ( 2. int i; 3. public void run
() ( 4. try ( 5. thread.sleep(5000); 6. i= 10; 7. )
catch(InterruptedException e) {} 8. ) 9. ) 10.   11. public
class Test { 12. public static void  main (string args[]) (
13. try ( 14. A a = new A (); 15. Thread t = new Thread (a);
16. t.start(); 17.   18. int j= a.i; 19.   20. ) catch
(Exception e) {} 21. ) 22. )    
Which statement al line 17 will ensure that 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();

59. 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 synchronized void run( ) (
12.      for (;(
13.       x++;
14.       y++;
15.       System.out.printIn(“x = “ +  x  + “, y = “ + y);
16.        )
17.     )
18. )
What is the result?
A.An error at line 11 causes compilation to fail.
B.Errors at lines 7 and 8 cause 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=2s, y=2”)

60. 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

61. 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.

62. Which method in the Thread class is used to create and
launch a new thread of execution?
A. run();
B. start();
C. execute();
D. run(Runnable r);
E. start(Runnable r);
F. execute(Thread t);

63. Given:
5. String foo = “base”;
6. foo.substring(0,3);
7. foo.concat(“ket”)
8.  
Type the value of foo at line 8.
Ans:  

64. 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);    

65. 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.

66. 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()

67. Click the exhibit button:
1. import java.awt.*; 2.   3. public class Test extends Frame
{ 4. public Test()  { 5. add(new Label(“Hello”)  ); 6. add(new
TextField(“Hello”)  ); 7. add(new Button(“Hello”)  ); 8.
pack(); 9. show(); 10. } 11.   12. public static void
main(String args[]) { 13.         new Test (); 14.  } 15. )  
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.

68. 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.

69. 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; }

70. 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 not require an instance of the
enclosing class.
D. Instance members of a static inner class can be referenced
using the class name of the static inner class.

71. 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.

72. Given:
AnInterface is an interface.
AnAdapter0 is a non-abstract, non-final class with a zero
argument constructor.
AnAdapter1 is a non-abstract, non-final class without a zero
argument constructor, but with a constructor that takes one
int argument.
Which two construct an anonymous inner class? (Choose Two)
A. AnAdapter1 aa=new AnAdapter1(){}
B. AnAdapter0 aa=new AnAdapter0(){}
C. AnAdapter0 aa=new AnAdapter0(5){}
D. AnAdapter1 aa=new AnAdapter1(5){}
E. AnInterface a1=new AnInterface(5){}

73. 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.

74. Click the exhibit button:
1. public class Mycircle { 2. public double radius; 3. public
double diameter; 4.   5. public void setRadius(double radius)
6. this.radius = radius; 7. this.diameter= radius * 2; 8. } 9.
  10. public double getRadius()   { 11. return radius; 12.  }
13. }  
Which statement is true?
A. The Mycircle class is fully encapsulated.
B. The diameter of a given MyCircle is guaranteed to be twice
its radius.
C. Lines 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.

75. 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

76. Click the exhibit button.
ClassOne.java 1. package com.abc.pkg1; 2. public class
ClassOne { 3. private char var = ‘a’;  4. char getVar()  
{return var;} 5. }  ClassTest.java   1. package com.abc.pkg2;
2. import com.abc.pkg1.ClassOne; 3. public class ClassTest
extends ClassOne { 4.   public static void main(String[]args)  
{ 5.     char a = new ClassOne().getVar(); 6.     char b = new
ClassTest().getVar();  7.   } 8. }    
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.

77. Given:
1. public class ArrayTest {
2. public static void main (String[]args)  {
3. float f1[], f2[];
4. f1 = new float [10];
5. f2 = f1;
6. System.out.printIn (“f2[0]=” + f2[0]);
7.  }
8. }
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.

78. 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.

79. 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

80. Given:
1. public abstract class Test {
2. public abstract void methodA();
3.  
4. public abstract void methodB()
5. {
6.   System.out.printIn(“Hello”);
7.  }
8. }
Which three changes (made independently) allow the code to
compile? (Choose Three)

A. Add a method body to methodA.
B. Replace lines 5-7 with a semicolon (“.”).
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 entirely and change class o interface
in line 1.

81. Which determines if “prefs” is a directory and exists 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;
}

82. Which two create an InputStream and open file the
“file.txt” for reading? (Choose Two)
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”));  

83. 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);

84. Which constructs a BufferedInputStream?
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”));

85. Which is a valid identifier?
A. false
B. default
C. _object
D. a-class

86. 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

87. 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

88. Given:
8. int index = 1;
9. String [] test = new String[3];
10. String foo = test[index];  
What is the result?
A. foo has the value “”
B. foo has the value null
C. an exception is thrown
D. the code will not compile

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

90. Given:
1. public class foo {
2. static String s;
3. public static void main (String[]args) {
4. system.out.printIn (“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.

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

92. Given:
1. String foo = “blue”;
2. Boolean[]bar = new Boolean [1];
3. if (bar[0])  {
4.   foo = “green”;
5. }
What is the result?
A.foo has the value of “”
B.foo has the value of null
C.foo has the value of “blue”
D.foo has the value of “green”
E.an exception is thrown
F.the code will not compile

93. 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 (s2.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.

94. Given:
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;
7.        }
8.      }
9.    }
What is the final value of i?
A.1
B.2
C.3
D.4
E.5

95. 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.

96. Which two are equivalent? (Choose Two)
A.16>4
B.16/2
C.16*4
D.16>>2
E.16/2^2
F.16>>>2

97. Click the exhibit button
1. public class X { 2. public static void main (String[]args)  
 { 3. int [] a = new int [1] 4. modify(a); 5.
System.out.printIn(a[0]); 6. } 7.   8. public static void
modify (int[] a)  { 9.   a[0] ++; 10.    } 11. }    
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 causes
compilation to fail.
E. An error “possible undefined variable” at line 9 causes
compilation to fail.

98. 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.

99. Given:
1. public class X {
2. public static void main (String[] args)  {
3.   byte b = 127;
4.   byte c = 126;
5.   byte d = b + c;
6.   }
7. }
Which statement is true?
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.

100. 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

101. Which statement is true?
A. The Error class is a untimeException.
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.

102. 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

103. Given:
1. switch (i)  {
2. default:
3. System.out.printIn(“Hello”);
4. )
What is the acceptable type for the variable i?
A.byte
B.long
C.float
D.double
E.object
F.A and B
G.C and D  

104. 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

105. 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.

106. 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”).

107. 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.

108. 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)

109. Given:
4. String foo = “base”;
5. foo.substring(0,3);
6. foo.concat(“ket”);
7. foo += “ball”;
8.  
Type the value of foo at line 8.

110. Given:
1. public class Test {
2. public static void leftshift(int i, int j) {
3.    i<<=j;
4. }
5. public static void main(String args[])  {
6. int i = 4, j = 2;
7. leftshift(i, j);
8. System.out.printIn(i);
9.   }
10. }
What is the result?
A.2
B.4
C.8
D.16
E.The code will not compile

111. 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)

112. Click the exhibit button:
1. public class X   { 2. private static int a; 3.   5. public
static void main (String[] args)  { 6. modify (a); 7. } 8.  
9. public static void modify (int a) { 10. a++; 11.    } 12. }

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. En error “possible undefined variable” at line 5 causes
compilation to fail.
E. En error “possible undefined variable” at line 10 causes
compilation to fail.

113. 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.

114. Which two are equivalent? (Choose Two)
A.3/2
B.3<2
C.3*4
D.3<<2
E.3*2^2
F.3<<<2

115. 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

116. Given:
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.compilation will fail
E.compilation will succeed but the program will throw an
exception at line 4

117. 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.

118. 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.

119. 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)  {}

120. Which type of event indicates a key pressed on a
java.awt.Component?
A. KeyEvent
B. KeyDownEvent
C. KeyPressEvent
D. KeyTypedEvent
E. KeyPressedEvent

121. 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 BordrLayout()); 12. Panel p = new
Panel (); 13. add(p, BorderLayout.NORTH); 14. Button b = new
Button (“North”); 15. p.add(b): 16. Button b = new Button
(“South”); 17. add(b1, BorderLayout.SOUTH): 18.   } 19. }    
Which two statements are true? (Choose Two)
A. The buttons labeled “North” and “South” will have the same
width
B. The buttons labeled “North” and “South” will have the same
height
C. The height of the button labeled “North” can very if the
Frame is resized
D. The height of the button labeled “South” can very 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

122. 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.

123. 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.

124. 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 access modifier is required

125. 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.

126. Given:
1. public class OuterClass {
2. private double d1  1.0;
3. //insert code here
4. }
You need to insert an inner class declaration at line2. Which
two inner class declarations are valid? (Choose Two)
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();
}

127. Which two declarations prevent the overriding of a
method? (Choose Two)
A. final void methoda()  {}
B. void final methoda() {}
C. static void methoda() {}
D. static final void methoda() {}
E. final abstract void methoda() {}

128. 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

129. 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)

130. Given:
1. public class ExceptionTest {
2. class TestException extends Exception {}
3. public void runTest () throws TestException {}
4. public void test () /* Point X*/  {
5. runTest ();
6.   }
7. }
At point X on line 4, which code can be added to make the code
compile?
A.throws Exception
B.catch (Exception e)
C.throws RuntimeException
D.catch (TestException e)
E.no code is necessary

131. Click the exhibit button:
1. public class SwitchTest { 2. public static void main
(String []args)  { 3. System.out.PrintIn(“value =”
+switchIt(4)); 4. } 5. public static int switchIt(int x)  { 6.
int j = 1; 7. switch (x) { 8. case 1: j++; 9. case 2: j++; 10.
case 3: j++; 11. case 4: j++; 12. case 5: j++; 13.
default:j++; 14. } 15. return j + x; 16. } 17. }  
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

132. Which four types of objects can be thrown using the throw
statement? (Choose Four)
A.error
B.event
C.object
D.exception
E.throwable
F.RuntimeException

133. 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  

134. 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.

135. Given:  
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 compilation to fail.
D. An error at line 6 causes the compilation to fail.    
E. “Running” is printed and the program exits.

136. Which constructs a DataOutputStream?
A. new dataInputStream(“in.txt”);
B. new dataInputStream(new file(“in.txt”));
C. new dataInputStream(new writer(“in.txt”));
D. new dataInputStream(new FileWriter(“in.txt”));
E. new dataInputStream(new InputStream(“in.txt”));
F. new dataInputStream(new FileInputStream(“in.txt”));

137. Which can be used to decode charS for output?
A. java.io.InputStream
B. java.io.EncodedReader
C. java.io.InputStreamReader
D. java.io.InputStreamWriter
E. java.io.BufferedInputStream

138. Given:
1. public class Test {
2. public static void main (String [] args)  {
3. string foo = “blue”;
4. string bar = foo;
5. foo = “green”;
6. System.out.printIn(bar);
7.    }
8. }
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”.

139. 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);      

140. Which two demonstrate encapsulation of data? (Choose Two)

A.Member data has 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.

141. Click on the exhibit button:
1. class A { 2. public String toString ()  { 3. return “4”; 4.
} 5. } 6. class B extends A { 7. 8.   public String toString
()   { 8. return super.toString()  + “3”; 9. } 10. } 11.
public class Test { 12.   public static void
main(String[]args)  { 13.      System.out.printIn(new B());
14.      } 15. }  

What is the result?
A. Compilation succeeds and 4 is printed.
B. Compilation succeeds and 43 is printed.
C. An error on line 9 causes compilation to fail.
D. An error on line 14 causes compilation to fail.
E. Compilation succeeds but an exception is thrown at line 9

142. Which two statements are true? (Choose Two)
A.An anonymous inner class can be declared inside of a method.
B.An anonymous inner class constructor can take arguments in
some situation.
C.An anonymous inner class that is a direct subclass that is a
direct subclass of Object can implement multiple interfaces .
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.Event 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 multiple
interfaces.

143. Given:
1. public class MethodOver {
2. private int x, y;
3. private float z;
4. public void setVar(int a, int b, float c){
5. x = a;
6. y = b;
7. z = c;
8.  }
9. }
Which two overload the setVar method? (Choose Two)
      A.void setVar (int a, int b, float c){
x = a;
y = b;
z = c;
}
B. public void setVar(int a, float c, int b) {
setVar(a, b, c);
}
C. public void setVar(int a, float c, int b) {
this(a, b, c);
}
D. public void setVar(int a, float b){
x = a;
z = b;
}
E. public void setVar(int ax, int by, float cz) {
x = ax;
y = by;
z = cz;
}

144. Which statements about static inner classes are true?
(Choose Two)
A. 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 access to the non-static members
of the outer class.
E. Static members of a static inner class can be referenced
using the class name of the static inner class.

145. Given:
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, eligible for
garbage collection?
A. Just after line 5
B. Just after line 6
C. Just after line 7
D. Just after line 8(that is, as the method returns)

146. Which two interfaces provide the capability to store
objects using a key-value pair? (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

147. Which interface does java.util.Hashable implement?
A. java.util.Map
B. java.util.List
C. java.util.Hashable
D. java.util.Collection

 

Answer Key:            
1. C
2. D,E
3. B
4. 5
5. D
6. JavaJavaC
7. B
8. A,C
9. A,C
10. B,D
11. D,E
12. D
13. A
14. D
15. A
16. A
17. B,C
18. A,D,F
19. D
20. F
21. B
22. C
23. D
24. C
25. C
26. A
27. B
28. D
29. F
30. A
31. F
32. C
33. A
34. C,D
35. E
36. B
37. B
38. A
39. F
40. B
41. D
42. A,B,C,D,E
43. C
44. D
45. C
46. C
47. E
48. D
49. A,B
50. B
51. A
52. 13423
53. C
54. B
55. A,E  56. A,D
57. B
58. C
59. E
60. A,C
61. D,E
62. B
63. base
64. E
65. D
66. B
67. B
68. B
69. C,E
70. C
71. C
72. B,D
73. A,D
74. B
75. B
76. B
77. A
78. D,E
79. E
80. B,D,F
81. D
82. B,E
83. C,E
84. F
85. C
86. B
87. C
88. B
89. A,B,C
90. B
91. B,E
92. F
93. A
94. B
95. A
96. D,F
97. B
98. B
99. B
100. E
101. D
102. E
103. A
104. B,D
105. A
106. D
107. N/A
108. A
109. baseball
110. B  111. A,B,F
112. A
113. B
114. C,D
112. A
113. B
114. C,D
115. B
116. D
117. A
118. E
119. C
120. A
121. B,E
122. D
123. A
124. E
125. C,E
126. C,E
127. A,D
128. B
129. A,D
130. B
131. A,D
132. A,D,E,F
133. A
134. B,E
135. C
136. F
137. C
138. D
139. F
140. D,E
141. B
142. A,B
143. B,D
144. C,E
145. C
146. A,E
147. A

                                    
1. C
2. D,E
3. B
4. 5
5. D
6. JavaJavaC
7. B
8. A,C
9. A,C
10. B,D
11. D,E
12. D
13. A
14. D
15. A
16. A
17. B,C
18. A,D,F
19. D
20. F
21. B
22. C
23. D
24. C
25. C
26. A
27. B
28. D
29. F
30. A
31. F
32. C
33. A
34. C,D
35. E
36. B
37. B
38. A
39. F
40. B
41. D
42. A,B,C,D,E
43. C
44. D
45. C
46. C
47. E
48. D
49. A,B
50. B
51. A
52. 13423
53. C
54. B
55. A,E
56. A,D
57. B
58. C
59. E
60. A,C
61. D,E
62. B
63. base
64. E
65. D
66. B
67. B
68. B
69. C,E
70. C
71. C
72. B,D
73. A,D
74. B
75. B
76. B
77. A
78. D,E
79. E
80. B,D,F
81. D
82. B,E
83. C,E
84. F
85. C
86. B
87. C
88. B
89. A,B,C
90. B
91. B,E
92. F
93. A
94. B
95. A
96. D,F
97. B
98. B
99. B
100. E
101. D
102. E
103. A
104. B,D
105. A
106. D
107. N/A
108. A
109. baseball
110. B
111. A,B,F
112. A
113. B
114. C,D
115. B
116. D
117. A
118. E
119. C
120. A
121. B,E
122. D
123. A
124. E
125. C,E
126. C,E
127. A,D
128. B
129. A,D
130. B
131. A,D
132. A,D,E,F
133. A
134. B,E
135. C
136. F
137. C
138. D
139. F
140. D,E
141. B
142. A,B
143. B,D
144. C,E
145. C
146. A,E
147. A
 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值