Q1. Given the code fragment:
What is the result?
A. Jesse 25 Walter 52
B. Compilation fails only at line n1
C. Compilation fails only at line n2
D. Compilation fails at both line n1 and line n2
Answer: D
Q2. Given the code fragment:
What is the result?
A. 28false29 true
B. 285 < 429 true
C. true true
D. compilation fails
Answer: C
Q3. Given the code fragment:
Which two modifications, when made independently, enable the code to print joe:true: 100.0?
A. Option A
B. Option B
C. Option C
D. Option D
E. Option E
Answer: A,C
Q4. Given:
class MarksOutOfBoundsException extends IndexOutOfBoundsException { }
public class GradingProcess {
void verify(int marks) throws IndexOutOfBoundsException {
if (marks > 100) {
throw new MarksOutOfBoundsException();
}
if (marks > 50) {
System.out.print("Pass");
} else {
System.out.print("Fail");
}
}
public static void main(String[] args) {
int marks = Integer.parseInt(args[2]);
try {
new GradingProcess().verify(marks));
} catch(Exception e) {
System.out.print(e.getClass()); } } }
And the command line invocation:
Java grading process 89 50 104
What is the result?
A. Pass
B. Fail
C. Class MarketOutOfBoundsException
D. Class IndexOutOfBoundsException
E. Class Exception
Answer: C
Explanation: The value 104 will cause a MarketOutOfBoundsException
Q5. Given:
What is the result?
A. 11, 21, 31, 11, 21, 31
B. 11, 21, 31, 12, 22, 32
C. 12, 22, 32, 12, 22, 32
D. 10, 20, 30, 10, 20, 30
Answer: D
Q6. Given the code fragment:
Which code fragment, when inserted at line n1, enables the App class to print Equal?
A. Option A
B. Option B
C. Option C
D. Option D
Answer: B
Q7. Given the following array:
Which two code fragments, independently, print each element in this array?
A. Option A
B. Option B
C. Option C
D. Option D
E. Option E
F. Option F
Answer: B,E
Explanation: All the remaining options have syntax errors
Q8. Given the code fragment
int var1 = -5;
int var2 = var1--;
int var3 = 0;
if (var2 < 0) {
var3 = var2++;
} else {
var3 = --var2;
}
System.out.println(var3);
What is the result?
A. – 6
B. – 4
C. – 5
D. 5
E. 4
F. Compilation fails
Answer: C
Q9. Given:
class Overloading {
int x(double d) {
System.out.println("one");
return 0;
}
String x(double d) {
System.out.println("two");
return null;
}
double x(double d) {
System.out.println("three");
return 0.0;
}
public static void main(String[] args) {
new Overloading().x(4.0);
}
}
What is the result?
A. One
B. Two
C. Three
D. Compilation fails.
Answer: D
Q10. Given the code fragment:
What is the result?
A. A B C
B. A B C D E
C. A B D E
D. Compilation fails.
Answer: C