Q1. Given the code fragment:
What is the result?
A. 2 2
B. 1 2
C. 3 2
D. 3 3
Answer: A
Q2. Given:
Given the code fragment:
What is the result?
A. 10 20 30 40
B. 0 0 30 40
C. Compilation fails
D. An exception is thrown at runtime
Answer: A
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:
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. Given:
Which two are possible outputs?
A. Option A
B. Option B
C. Option C
D. Option D
Answer: AD
Q6. 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
Q7. Given the code fragment:
What values of x, y, z will produce the following result?
1 2 3 4
1 2 3 4
1 2 3 4
1 2 3 4
A. X = 4, Y = 3, Z = 2
B. X = 3, Y = 2, Z = 3
C. X = 2, Y = 3, Z = 3
D. X = 4, Y = 2, Z = 3
E. X = 2, Y = 3, Z = 4
Answer: E
Q8. Given:
What is the result?
A. Shining Sun
Shining Sun
Shining Sun
B. Shining Sun
Twinkling Star
Shining Sun
C. Compilation fails
D. A ClassCastException is thrown at runtime
Answer: D
Q9. Given the fragments:
Which line causes a compilation error?
A. Line n1
B. Line n2
C. Line n3
D. Line n4
Answer: A
Q10. Given:
What code should be inserted?
A. Option A
B. Option B
C. Option C
D. Option D
E. Option E
F. Option F
Answer: C