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. 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
Q3. Given:
What is the reference type of myZ and what is the type of the object it references?
A. Reference type is Z; object type is Z.
B. Reference type is Y; object type is Y.
C. Reference type is Z; object type is Y.
D. Reference type is X; object type is Z.
Answer: C
Q4. 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
Q5. Which code fragments, inserted independently, enable the code compile?
A. t.fvar = 200;
B. cvar = 400;
C. fvar = 200; cvar = 400;
D. this.fvar = 200; this.cvar = 400;
E. t.fvar = 200; Test2.cvar = 400;
F. this.fvar = 200; Test2.cvar = 400;
Answer: B
Q6. Given:
What is the result?
A. 2 4 6 8 10 12
B. 2 4 6 8 10 12 14
C. Compilation fails
D. The program prints multiple of 2 infinite times
E. The program prints nothing
Answer: B
Q7. 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
Q8. Which three are advantages of the Java exception mechanism?
A. Improves the program structure because the error handling code is separated from the
normal program function
B. Provides a set of standard exceptions that covers all the possible errors
C. Improves the program structure because the programmer can choose where to handle
exceptions
D. Improves the program structure because exceptions must be handled in the method in
which they occurred
E. allows the creation of new exceptions that are tailored to the particular program being
Answer: ACE
Q9. What is the result?
A. Valid
B. Not valid
C. Compilation fails
D. An IllegalArgumentException is thrown at run time
Answer: C
Q10. Given:
What is the result?
A. Null
B. Compilation fails
C. An exception is thrown at runtime
D. 0
Answer: A