问题 1
Analyze the following code.
public class Test {
int x;
public Test(String t) {
System.out.println("Test");
}
public static void main(String[] args) {
Test test = new Test();
System.out.println(test.x);
}
}
A.The program has a compile error because x has not been initialized.
B.The program has a compile error because you cannot create an object from the class that defines the object.
C.The program has a compile error because Test does not have a default constructor.
D.The program has a compile error because System.out.println method cannot be invoked from the constructor.
问题2
The java.util.Date class is introduced in this section. Analyze the following code and choose the best answer:
Which of the following code in A or B, or both creates an object of the Date class:
A:
public class Test {
public Test() {
new java.util.Date();
}
}
B:
public class Test {
public Test() {
java.util.Date date = new java.util.Date();
}
}
A.A.
B.Neither
C.B.
问题 3
What code may be filled in the blank without causing syntax or runtime errors:
public class Test {
java.util.Date date;
public static void main(String[] args) {
Test test = new Test();
System.out.println(_________________);
}
}
A.test.date
B.test.date.toString()
C.date.toString()
D.date
问题 4
What is the output of the following program?
import java.util.Date;
public class Test {
public static void main(String[] args) {
Date date = new Date(1234567);
m1(date);
System.out.print(date.getTime() + " ");
m2(date);
System.out.println(date.getTime());
}
public static void m1(Date date) {
date = new Date(7654321);
}
public s