No9
Given:
1. class TestA {
2. TestB b;
3. TestA() {
4. b = new TestB(this);
5. }
6. }
7. class TestB {
8. TestA a;
9. TestB(TestA a) {
10. this.a = a;
11. }
12. }
13. class TestAll {
14. public static void main (String args[]) {
15. new TestAll().makeThings();
16. // ...code continues on
17. }
18. void makeThings() {
19. TestA test = new TestA();
20. }
21. }
Which two statements are true after line 15, before main completes? (Choose two)
A. Line 15 causes a stack overflow.
B. An exception is thrown at runtime.
C. The object referenced by a is eligible for garbage collection.
D. The object referenced by b is eligible for garbage collection.
E. The object referenced by a is not eligible for garbage collection.
F. The object referenced by b is not eligible for garbage collection.No10
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.util.Map 
 B.java.util.Set 
 C.java.util.List 
 D.java.util.SortedSet 
 E.java.util.SortedMap 
 F.java.util.Collection No11
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.No12
Given:
1. package test1;
2. public class Test1 {
3. static int x = 42;
4. }
1. package test2;
2. public class Test2 extends test1.Test1 {
3. public static void main(String[] args) {
4. System.out.println(“x = “ + x);
5. }
6. }
What is the result?
A. x = 0
B. x = 42
C. Compilation fails because of an error in line 2 of class Test2.
D. Compilation fails because of an error in line 3 of class Test1.
E. Compilation fails because of an error in line 4 of class Test2.No13
Which statement is true?
A. The Error class is a runtimeException.
B. No exceptions are subclasses of Error.
C. Any statement that may throw an Error must be enclosed in a try block.
D. Any statement that may throw an Exception must be enclosed in a try block.
E. Any statement that may thro a runtimeException must be enclosed in a try block.
 
No14
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.

解决方案 »

  1.   

    No1.选B
    A.Mycircle类被完全封装。错:因为它的成员变量都是public的。
    B.这个类的diameter成员必定是radius的两倍。对:见第7行。而且初始时它们都为0,也满足两倍关系。
    C.第6,7行应该被写在synochronized中以保证该类的封装。错:因为封装是与它的成员变量的属性有关,与是否synochronized无关。
    D.改变radius属性时不会影响到diameter属性。错:同样见第7行。No2.选CE
    A.默认的构造方法初始化局部变量。
    B.编译器总是为每一个类创建一个默认的构造方法。
    C.默认的构造方法会调用父类的无参构造方法。
    D.默认的构造方法初始化实例变量。
    E.当一个类只有带参数的构造方法时,编译器就不会创建默认的构造方法。No3.选CNo4.选BENo5.选ENo6.选BNo7.选DNo8.选B
      

  2.   

    楼上的,第一题明显是D,
    2. public double radius;
    3. public double diameter;
      

  3.   

    No.9选CD
    class TestA {
    TestB b;
    TestA() {
    System.out.println("TestA");
    b = new TestB(this);
    }
    }class TestB {
    TestA a;
    TestB(TestA a) {
    this.a = a;
    System.out.println("TestB");
    }
    }
    输出结果是:
    TestA
    TestB
    我想大家就会明白一些。执行过程是先加载TestA,然后执行构造函数,b = new TestB(this);
    这个时候才加载类TestB。
      

  4.   

    No10.选BNo11.选ANo12.选E
    static int x = 42; x只有包的访问权限,包test2中的类无法访问他。No13.选DNo14.选AD
    一匿名内部类不能有构造方法,二不能有多个实现接口
      

  5.   

    maowu,我觉得第7行能够说明第一题的问题吧。
      

  6.   

    No 1 确实是D 可以直接访问域中变量而不必通过构造函数guaranteed 可以翻译为"确保"
      

  7.   

    以前没见过SCJP的题目,今天见了,开眼了,觉得SCJP真tm没用