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. What is the result?
A. Hello
B. Default
C. Compilation fails
D. The program prints nothing
E. An exception is thrown at run time
Answer: A
Q3. 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
Q4. Given:
public class MainMethod {
void main() {
System.out.println("one");
}
static void main(String args) {
System.out.println("two");
}
public static void main(String[] args) {
System.out.println("three");
}
void mina(Object[] args) {
System.out.println("four");
}
}
What is printed out when the program is excuted?
A. one
B. two
C. three
D. four
Answer: C
Q5. 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
Q6. 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
Q7. An unchecked exception occurs in a method dosomething() Should other code be added in the dosomething() method for it to compile and execute?
A. The Exception must be caught
B. The Exception must be declared to be thrown.
C. The Exception must be caught or declared to be thrown.
D. No other code needs to be added.
Answer: D
Q8. Given:
What is the result?
A. 2 1
B. 2 1 0
C. null
D. an infinite loop
E. compilation fails
Answer: E
Q9. Given the code fragment:
Boolean b1 = true;
Boolean b2 = false;
int i = 0;
while (foo) { }
Which one is valid as a replacement for foo?
A. b1.compareTo(b2)
B. i = 1
C. i == 2? -1 : 0
D. "foo".equals("bar")
Answer: D
Q10. Int [] [] array = {{0}, {0, 1}, {0, 2, 4}, {0, 3, 6, 9}, {0, 4, 8, 12, 16}};
Systemout.printIn(array [4] [1]);
System.out.printIn (array) [1] [4]);
What is the result?
A. 4 Null
B. Null 4
C. An IllegalArgumentException is thrown at run time
D. 4 An ArrayIndexOutOfBoundException is thrown at run time
Answer: D
Q11. public class Two {
public static void main(String[] args) {
try {
doStuff();
system.out.println("1");
}
catch {
system.out.println("2");
}}
public static void do Stuff() {
if (Math.random() > 0.5) throw new RunTimeException(); doMoreStuff();
System.out.println("3 ");
}
public static void doMoreStuff() {
System.out.println("4");
}
}
Which two are possible outputs?
A. 2
B. 4 3 1
C. 1
D. 1 2
Answer: AB
Q12. 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
Q13. Why will the code not compile?
A. A static field cannot be private.
B. The getLetter method has no body.
C. There is no setLetter method.
D. The letter field is uninitialized.
E. It contains a method named Main instead of ma
Answer: B
Q14. Given:
What is the result?
A. One
B. Two
C. Three
D. Compilation fails
Answer: C
Q15. Given:
What is the result?
A. The sum is 2
B. The sum is 14
C. The sum is 15
D. The loop executes infinite times
E. Compilation fails
Answer: D
Q16. public class ForTest {
public static void main(String[] args) {
int[] arrar = {1,2,3};
for ( foo ) {
}
}
}
Which three are valid replacements for foo so that the program will compiled and run?
A. int i: array
B. int i = 0; i < 1; i++
C. ;;
D. ; i < 1; i++
E. ; i < 1;
Answer: ABC