Q1. for ( expr1 ; expr2 ; expr3 ) {
statement;
}
Which two statements are true?
A. This is not the only valid for loop construct; there exits another form of for loop
constructor.
B. The expression expr1 is optional. it initializes the loop and is evaluated once, as the loop
begin.
C. When expr2 evaluates to false, the loop terminates. It is evaluated only after each
iteration through the loop.
D. The expression expr3 must be present. It is evaluated after each iteration through the
loop.
Answer: BC
Q2. Given the fragments:
Which line causes a compilation error?
A. Line n1
B. Line n2
C. Line n3
D. Line n4
Answer: A
Q3. 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
Q4. Which code fragment, when inserted at line 9, enables the code to print true?
A. String str2 = str1;
B. String str2 = new string (str1);
C. String str2 = sb1.toString();
D. String str2 = “Duke”;
Answer: B
Q5. Given the code fragment:
What is the result?
A. 2 2
B. 1 2
C. 3 2
D. 3 3
Answer: A
Q6. 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
Q7. Given:
What is the result?
A. box
B. nbo
C. bo
D. nb
E. An exception is thrown at runtime
Answer: A
Q8. Given:
What is the result?
A. 2 4 6 8
B. 2 4 6 8 9
C. 1 3 5 7
D. 1 3 5 7 9
Answer: D
Q9. The catch clause argument is always of type__________.
A. Exception
B. Exception but NOT including RuntimeException
C. Throwable
D. RuntimeException
E. CheckedException
F. Error
Answer: C
Q10. 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