Q1. 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
Q2. Given:
public class ScopeTest {
int j, int k;
public static void main(String[] args) {
ew ScopeTest().doStuff(); }
void doStuff() {
nt x = 5;
oStuff2();
System.out.println("x");
}
void doStuff2() {
nt y = 7;
ystem.out.println("y");
or (int z = 0; z < 5; z++) {
ystem.out.println("z");
ystem.out.println("y");
}
which two items are fields?
A. j
B. k
C. x
D. y
E. z
Answer: AB
Q3. Given:
Which code fragment, when inserted at line 14, enables the code to print Mike Found?
A. int f = ps.indexOf {new patient (“Mike”)};
B. int f = ps.indexOf (patient(“Mike”));
C. patient p = new Patient (“Mike”);
int f = pas.indexOf(P)
D. int f = ps.indexOf(p2);
Answer: C
Q4. Given the code fragment:
A. 20
B. 25
C. 29
D. Compilation fails
E. An Array Index Out Of Bounds Exception is thrown at runtime
Answer: B
Q5. What is the result?
A. They match They really match
B. They really match
C. They match
D. Nothing Prints
E. They really match They really match
Answer: B
Q6. which three lines are illegal?
A. line 3
B. line 4
C. line 5
D. line 6
E. line 10
F. line 11
G. line 12
H. line 13
Answer: CDH
Q7. Given:
Which three lines will compile and output “right on!”?
A. Line 5
B. Line 6
C. Line 7
D. Line 8
E. Line 9
F. Line 10
Answer: CDF
Q8. Which two are valid array declaration?
A. Object array[];
B. Boolean array[3];
C. int[] array;
D. Float[2] array;
Answer: AC
Q9. Given a code fragment:
A. They match They real match
B. They really match
C. They match
D. Nothing is printed to the screen
Answer: B
Q10. Given:
A. Ym
Xm2
B. Ym
Xm1
C. Compilation fails
D. A Class Cast Exception is thrown at runtime
Answer: B