Q1. Given:
A. Good Day!
Good Luck!
B. Good Day!
Good Day!
C. Good Luck!
Good Day!
D. Good Luck!
Good Luck!
E. Compilation fails
Answer: E
Q2. Given the code format:
Which code fragment must be inserted at line 6 to enable the code to compile?
A. DBConfiguration f; return f;
B. Return DBConfiguration;
C. Return new DBConfiguration;
D. Retutn 0;
Answer: B
Q3. Given:
And the commands:
Javac Test.java
Java Test 12345
What is the result?
A. Number us : 12345
B. A NullPointerException is thrown at runtime
C. A NumberFormatException is thrown at runtime
D. AnArrayIndexOutOfBoundException is thrown at runtime.
Answer: A
Q4. Which two are valid array declaration?
A. Object array[];
B. Boolean array[3];
C. int[] array;
D. Float[2] array;
Answer: AC
Q5. A method doSomething () that has no exception handling code is modified to trail a method that throws a checked exception. Which two modifications, made independently, will allow the program to compile?
A. Catch the exception in the method doSomething().
B. Declare the exception to be thrown in the doSomething() method signature.
C. Cast the exception to a RunTimeException in the doSomething() method.
D. Catch the exception in the method that calls doSomething().
Answer: AB
Q6. Given:
Which line causes a compilation error?
A. line x1
B. line x2
C. line x3
D. line x4
Answer: B
Q7. class Overloading {
int x(double d) {
System.out.println("one");
return 0;
}
String x(double d) {
System.out.println("two");
return null;
}
double x(double d) {
System.out.println("three");
return 0.0;
}
public static void main(String[] args) {
new Overloading().x(4.0);
}
}
What is the result?
A. One
B. Two
C. Three
D. Compilation fails.
Answer: D
Q8. Given the code fragment:
System.out.printIn("Result: " + 2 + 3 + 5);
System.out.printIn("Result: " + 2 + 3 * 5);
What is the result?
A. Result: 10
Result: 30
Result: 10
Result: 25
C. Result: 235
Result: 215
D. Result: 215
Result: 215
E. Compilation fails
Answer: C
Q9. Given the fragments:
Which line causes a compilation error?
A. Line n1
B. Line n2
C. Line n3
D. Line n4
Answer: A
Q10. Given:
What is the result?
A. 0
B. 0 1 2
C. 0 1 2 0 1 2 0 1 2
D. Compilation fails
Answer: B
Q11. Given:
What is the result?
A. box
B. nbo
C. bo
D. nb
E. An exception is thrown at runtime
Answer: A
Q12. A method is declared to take three arguments. A program calls this method and passes only two arguments. What is the results?
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 falsy value for its declared type.
F. An exception occurs when the method attempts to access the third argument.
Answer: A
Q13. Given:
What is the result?
A. 10 : 22 : 20
B. 10 : 22 : 22
C. 10 : 22 : 6
D. 10 : 30 : 6
Answer: B
Q14. Given:
What is the result?
A. The program prints nothing
B. d
C. A S StringIndexOutOfBoundsException is thrown at runtime.
D. AnArrayIndexOutOfBoundsException is thrown at runtime.
E. A NullPointerException is thrown at runtime.
Answer: C
Q15. ArrayList<Integer> list = new ArrayList<>(1);
2. list.add(1001);
3. list.add(1002);
4. System.out.println(list.get(list.size()));
What is the result?
A. Compilation fails due to an error on line 1.
B. An exception is thrown at run time due to error on line 3
C. An exception is thrown at run time due to error on line 4
D. 1002
Answer: C
Q16. What is the result when this program is executed?
A. Bob's Name: Bob
B. Bob's Name: Jian
C. Nothing prints
D. Bob’s name
Answer: B