Q1. 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
Q2. 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
Q3. Given:
What is the result?
A. null
B. compilation fails
C. Java.lang.NullPointerException
D. 0
Answer: A
Q4. Given:
What is the result?
A. x: 1 y: 2
B. 3 y: 4
C. x: 0 y: 0
D. 3 y: 4
E. x: 1 y: 2
F. 0 y: 0
G. x: 0 y: 0
H. 0 y: 0
Answer: C
Q5. Given a java source file:
What changes will make this code compile? (Select Two)
A. Adding the public modifier to the declaration of class x
B. Adding the protected modifier to the x() constructor
C. Changing the private modifier on the declaration of the one() method to protected
D. Removing the Y () constructor
E. Removing the private modifier from the two () method
Answer: CE
Q6. Given:
What will be the output?
A. Option A
B. Option B
C. Option C
D. Option D
Answer: D
Q7. Which two statements are true?
C. An interface CANNOT be extended by another interface.
D. An interface can be extended by an abstract class.
E. An abstract class can be extended by a concrete class.
F. An abstract class CANNOT be extended by an abstract class.
Answer: AE
Q8. 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
Q9. Given:
What is the result?
A. 2 1
B. 2 1 0
C. null
D. an infinite loop
E. compilation fails
Answer: E
Q10. What is the result?
A. Valid
B. Not valid
C. Compilation fails
D. An IllegalArgumentException is thrown at run time
Answer: C
Q11. 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
Q12. Which statement initializes a stringBuilder to a capacity of 128?
A. StringBuilder sb = new String ("128");
B. StringBuilder sb = StringBuilder.setCapacity (128);
C. StringBuilder sb = StringBuilder.getInstance (128);
D. StringBuilder sb = new StringBuilder (128);
Answer: D
Q13. 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
Q14. 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
Q15. The protected modifier on a Field declaration within a public class means that the field
______________.
A. Cannot be modified
B. Can be read but not written from outside the class
C. Can be read and written from this class and its subclasses only within the same
package
D. Can be read and written from this class and its subclasses defined in any package
Answer: D
Q16. What is the result if the integer aVar is 9?
A. 10 Hello world!
B. 10 Hello universe!
C. 9 Hello world!
D. Compilation fails.
Answer: C