Q1. Given:
Which two are possible outputs?
A. Option A
B. Option B
C. Option C
D. Option D
Answer: AD
Q2. int [] array = {1,2,3,4,5};
for (int i: array) {
if ( i < 2) {
keyword1 ;
}
System.out.println(i);
if ( i == 3) {
keyword2 ;
}}
What should keyword1 and keyword2 be respectively, in oreder to produce output 2345?
A. continue, break
B. break, break
C. break, continue
D. continue, continue
Answer: D
Q3. Given the code fragment:
nt a = 0;
a++;
System.out.printIn(a++);
System.out.printIn(a);
What is the result?
A. 1 2
B. 0 1
C. 1 1
D. 2 2
Answer: A
Q4. Given:
What is the result?
A. 6 5 6 4
B. 6 5 5 4
C. 6 5 6 6
D. 6 5 6 5
Answer: A
Q5. 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
Q6. 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
Q7. Which two may precede the word ‘class’ in a class declaration?
A. local
B. public
C. static
D. volatile
E. synchronized
Answer: BC
Q8. Give:
What value should replace kk in line x to cause jj = 5 to be output?
A. -1
B. 1
C. 5
D. 8
E. 11
Answer: E
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. X XX
B. X Y X
C. Y Y X
D. Y YY
Answer: D