Q1. Given:
Which code fragment, when inserted at line 7, enables the code print true?
A. Option A
B. Option B
C. Option C
D. Option D
Answer: A
Q2. Why will the code not compile?
A. A static field cannot be private.
B. The getLetter method has no body.
C. There is no setLetter method.
D. The letter field is uninitialized.
E. It contains a method named Main instead of ma
Answer: B
Q3. Given:
What is the result?
A. hEllOjAvA!
B. Hello java!
C. Out of limits hEllOjAvA!
D. Out of limits
Answer: D
Q4. Give:
What is the result?
A. 1525
B. 13
C. Compilation fails
D. An exception is thrown at runtime
E. The program fails to execute due to runtime error
Answer: D
Q5. Given:
What should statement1, statement2, and statement3, be respectively, in order to produce the result?
Shape: constructor
Square: foo
Shape: foo
A. Option A
B. Option B
C. Option C
D. Option D
E. Option E
Answer: D
Q6. Given the code fragment:
String h1 = "Bob";
String h2 = new String ("Bob");
What is the best way to test that the values of h1 and h2 are the same?
A. if (h1 = = h2)
B. if (h1.equals(h2))
C. if (h1 = = h2)
D. if (h1.same(h2))
Answer: B
Q7. Given:
How many times is 2 printed as a part of the output?
A. Zero
B. Once
C. Twice
D. Thrice
E. Compilation fails.
Answer: D