Question 1
Given the declaration Circle x = new Circle(), which of the following statement is most accurate?
◦ x contains an object of the Circle type.
◦ x contains an int value.
◦ You can assign an int value to x.
◦ x contains a reference to a Circle object.
Question 2
Analyze the following code.
public class Test {
int x;
public Test(String t) {
| System.out.println("Test"); |
}
public static void main(String[] args) {
| System.out.println(test.x); |
}
}
◦ The program has a compile error because Test does not have a default constructor.
◦ The program has a runtime NullPointerException because test is null while executing test.x.
◦ The program has a compile error because you cannot create an object from the class that defines the object.
◦ The program has a compile error because x has not been initialized.
◦ The program has a compile error because test is not initialized.