1)What is the output of running class Test?
public classTest {public static voidmain(String[ ] args) {newCircle9();
}
}public abstract classGeometricObject {protectedGeometricObject() {
System.out.print("A");
}protected GeometricObject(String color, booleanfilled) {
System.out.print("B");
}
}public class Circle9 extendsGeometricObject {/**Default constructor*/
publicCircle9() {this(1.0);
System.out.print("C");
}/**Construct circle with a specified radius*/
public Circle9(doubleradius) {this(radius, "white", false);
System.out.print("D");
}/**Construct a circle with specified radius, filled, and color*/
public Circle9(double radius, String color, booleanfilled) {super(color, filled);
System.out.print("E");
}
}
A)CBAE B)BACD C)ABCD D)BEDC E)AEDC
调用过程:先初始化一个Circle9对象时,需要调用Circle9的缺省参数的构造函数Circle9() ,而这个缺省参数的构造函数调用Circle9(double radius) ,而Circle9(double radius) 又调用Circle9(double radius, String color, boolean filled) ,而Circle9(double radius, String color, boolean filled)需要调用其父类构造函数GeometricObject(String color, boolean filled)这样层层调用,在调用栈中就是BEDC
2)Which of the following class definitions defines a legal abstract class? 4) _______
A)abstract class A { abstract void unfinished(); }
B)class A { abstract void unfinished() { } }
C)public class abstract A { abstract void unfinished(); }
D)class A { abstract void unfinished(); }
abstract要写在 class或void之前
3)Which of the following statements are correct? (Choose all that apply.) 6) _______
A)Number i = 4.5; B) Double i = 4.5; C)Object i = 4.5; D) Integer i = 4.5;
Number类是数值包装类的抽象父类,Object是所有类的父类
4)The printout from the following code is ________.
java.util.ArrayList list = newjava.util.ArrayList();
list.add("New York");
java.util.ArrayList list1=list;
list.add("Atlanta");
list1.add("Dallas");
System.out.println(list1);
A)[New York, Atlanta, Dallas]B) [New York, Atlanta] C)[New York, Dallas] D) [New York]
注意这里的list1不是new出来的,与list指向相同的内存区域
5)Analyze the following code.
public classTest {public static voidmain(String[ ] args) {
Number x= new Integer(3);
System.out.println(x.intValue());
System.out.println((Integer)x.compareTo(new Integer(4)));
}
}
A)The program has a compile error because the member access operator (.) is executed before the casting operator.
B)The program has a compile error because an Integer instance cannot be assigned to a Number variable.
C)The program has a compile error because x cannot be cast into Integer.
D)The program has a compil