9 A+ ACCELERATOR – MASTER
TREE TRAVERSALS, HEAPS &
RECURSION FIRST TIME
Given the declaration Circle x = new Circle(), which of
the following statement is most accurate.
A. x contains an int value.
B. x contains an object of the Circle type.
C. x contains a reference to a Circle object.
D. You can assign an int value to x - THE CORRECT ANSWER-C
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 = null;
System.out.println(test.x);
}
}
A. The program has a compile error because test is not
initialized.
B. The program has a compile error because x has not
been initialized.
C. The program has a compile error because you cannot
create an object from the class that defines the object.
D. The program has a compile error because Test does
not have a default constructor.
E. The program has a runtime NullPointerException
because test is null while executing test.x. - THE CORRECT
ANSWER-E
The default value for data field of a boolean type,
numeric type, object type is ___________,
respectively.
A. true, 1, Null
B. false, 0, null
C. true, 0, null
D. true, 1, null
E. false, 1, null - THE CORRECT ANSWER-B
,Which of the following statements are true?
A. Local variables do not have default values.
B. Data fields have default values.
C. A variable of a primitive type holds a value of the
primitive type.
D. A variable of a reference type holds a reference to
where an object is stored in the memory.
E. You may assign an int value to a reference variable. -
THE CORRECT ANSWER-A, B, C and D
Analyze the following code:
public class Test {
public static void main(String[] args) {
double radius;
final double PI= 3.15169;
double area = radius * radius * PI;
System.out.println("Area is " + area);
}
}
A. The program has compile errors because the variable
radius is not initialized.
, B. The program has a compile error because a constant
PI is defined inside a method.
C. The program has no compile errors but will get a
runtime error because radius is not initialized.
D. The program compiles and runs fine. - THE CORRECT
ANSWER-A
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
System.out.println method cannot be invoked from the
constructor.