Q1. Given the code fragments:
What is the result?
A. Super
Sub
Sub
B. Contract
Contract
Super
C. Compilation fails at line n1
D. Compilation fails at line n2
Answer: D
Q2. What is the result if the integer aVar is 9?
A. 10 Hello world!
B. 10 Hello universe!
C. 9 Hello world!
D. Compilation fails.
Answer: C
Q3. Given the fragment:
What is the result?
A. 13480.0
B. 13480.02
C. Compilation fails
D. An exception is thrown at runtime
Answer: C
Q4. What is result?
A. Successful
B. Unsuccessful
C. Compilation fails
D. An exception is thrown at runtime
Answer: C
Q5. Given:
public class Main {
public static void main(String[] args) {
try {
doSomething();
}
catch (SpecialException e) {
System.out.println(e);
}}
static void doSomething() {
int [] ages = new int[4];
ages[4] = 17;
doSomethingElse();
}
static void doSomethingElse() {
throw new SpecialException("Thrown at end of doSomething() method"); }
}
What is the output?
A. SpecialException: Thrown at end of doSomething() method
B. Error in thread "main" java.lang.
ArrayIndexOutOfBoundseror
C. Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 4
at Main.doSomething(Main.java:12)
at Main.main(Main.java:4)
D. SpecialException: Thrown at end of doSomething() method at
Main.doSomethingElse(Main.java:16)
at Main.doSomething(Main.java:13)
at Main.main(Main.java:4)
Answer: C
Q6. 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
Q7. Given:
Javac Jump.java
Java Jump crazy elephant is always
What is the result?
A. Lazy lion is jumping
B. Lion is always jumping
C. Crazy elephant is jumping
D. Elephant is always jumping
E. Compilation fails
Answer: B
Q8. 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
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. Given:
What is the result?
A. Marrown
String out of limits
JesOran
B. Marrown
String out of limits
Array out of limits
C. Marrown
String out of limits
D. Marrown
NanRed
JesOran
Answer: D