Q1. Given the code fragment:
What is the result?
A. 2 2
B. 1 2
C. 3 2
D. 3 3
Answer: A
Q2. What is the result?
A. Initialized
Started
B. Initialized
Started
Initialized
C. Compilation fails
D. An exception is thrown at runtime
Answer: B
Q3. Which two statements are true for a two-dimensional array?
A. It is implemented as an array of the specified element type.
B. Using a row by column convention, each row of a two-dimensional array must be of the same size.
C. At declaration time, the number of elements of the array in each dimension must be specified.
D. All methods of the class Object may be invoked on the two-dimensional array.
Answer: AD
Q4. Given:
Which two are possible outputs?
A. Option A
B. Option B
C. Option C
D. Option D
Answer: AD
Q5. Give:
What value should replace kk in line x to cause jj = 5 to be output?
A. -1
B. 1
C. 5
D. 8
E. 11
Answer: E
Q6. Given the code fragment:
What values of x, y, z will produce the following result?
1 2 3 4
1 2 3 4
1 2 3 4
1 2 3 4
A. X = 4, Y = 3, Z = 2
B. X = 3, Y = 2, Z = 3
C. X = 2, Y = 3, Z = 3
D. X = 4, Y = 2, Z = 3
E. X = 2, Y = 3, Z = 4
Answer: E
Q7. Given:
Javac Jump.java
Java Jump crazy elephant is always
What is the result?
A. Lazy lion is jumping
B. Lion is always jumping
C. Crazy elephant is jumping
D. Elephant is always jumping
E. Compilation fails
Answer: B
Q8. Given:
What is the result?
A. There is no output
B. d is output
C. A StringIndexOutOfBoundsException is thrown at runtime
D. An ArrayIndexOutOfBoundsException is thrown at runtime
E. A NullPointException is thrown at runtime
F. A StringArrayIndexOutOfBoundsException is thrown at runtime
Answer: C
Q9. Given the code fragment:
Which code fragment prints blue, cyan, ?
A. Option A
B. Option B
C. Option C
D. Option D
Answer: B
Q10. Given the code fragment:
Which statement is true?
A. After line 8, three objects are eligible for garbage collection
B. After line 8, two objects are eligible for garbage collection
C. After line 8, one object is eligible for garbage collection
D. After line 8, none of the objects are eligible for garbage collection
Answer: C
Q11. Which two are valid declarations of a two-dimensional array?
A. int [] [] array2D;
B. int [2] [2] array2D;
C. int array2D [];
D. int [] array2D [];
E. int [] [] array2D [];
Answer: AD
Q12. Given the class definitions:
And the code fragment of the main() method,
What is the result?
A. Java
Java
Java
B. Java
Jeve
va
C. Java
Jeve
ve
D. Compilation fails
Answer: D
Q13. Given the fragment:
What is the result?
A. 13480.0
B. 13480.02
C. Compilation fails
D. An exception is thrown at runtime
Answer: C
Q14. Which code fragment is illegal?
A. Option A
B. Option B
C. Option C
D. Option D
Answer: D
Q15. Given the code fragment:
interface SampleClosable {
public void close () throws java.io.IOException;
}
Which three implementations are valid?
A. Option A
B. Option B
C. Option C
D. Option D
E. Option E
Answer: ACE
Q16. A method is declared to take three arguments. A program calls this method and passes only two arguments. What is the result?
A. Compilation fails.
B. The third argument is given the value null.
C. The third argument is given the value void.
D. The third argument is given the value zero.
E. The third argument is given the appropriate false value for its declared type.
F. An exception occurs when the method attempts to access the third argument.
Answer: A