Q1. Given:
What is the result?
A. 2 4 6 8
B. 2 4 6 8 9
C. 1 3 5 7
D. 1 3 5 7 9
Answer: D
Q2. Given the code fragment:
System.out.printIn("Result: " + 2 + 3 + 5);
System.out.printIn("Result: " + 2 + 3 * 5);
What is the result?
A. Result: 10
Result: 30
Result: 10
Result: 25
C. Result: 235
Result: 215
D. Result: 215
Result: 215
E. Compilation fails
Answer: C
Q3. 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
Q4. Given:
What is the result?
A. 7
B. 12
C. 19
D. Compilation fails
E. An exception is thrown at run time
Answer: B
Q5. Given:
A. Good Day!
Good Luck!
B. Good Day!
Good Day!
C. Good Luck!
Good Day!
D. Good Luck!
Good Luck!
E. Compilation fails
Answer: E
Q6. Which is a valid abstract class?
A. public abstract class Car {
protected void accelerate();
}
B. public interface Car {
protected abstract void accelerate();
}
C. public abstract class Car {
protected final void accelerate();
}
D. public abstract class Car {
protected abstract void accelerate();
}
E. public abstract class Car {
protected abstract void accelerate() {
//more car can do
}}
Answer: D
Q7. Given:
How many times is 2 printed as a part of the output?
A. Zero
B. Once
C. Twice
D. Thrice
E. Compilation fails.
Answer: D
Q8. Given:
A. X XX
B. X Y X
C. Y Y X
D. Y YY
Answer: D
Q9. Which two are Java Exception classes?
A. SercurityException
B. DuplicatePathException
C. IllegalArgumentException
D. TooManyArgumentsException
Answer: AC
Q10. Given:
What is the result?
A. The program prints nothing
B. d
C. A S StringIndexOutOfBoundsException is thrown at runtime.
D. AnArrayIndexOutOfBoundsException is thrown at runtime.
E. A NullPointerException is thrown at runtime.
Answer: C
Q11. Given:
Which approach ensures that the class can be compiled and run?
A. Put the throw new Exception() statement in the try block of try – catch
B. Put the doSomethingElse() method in the try block of a try – catch
C. Put the doSomething() method in the try block of a try – catch
D. Put the doSomething() method and the doSomethingElse() method in the try block of a try – catch
Answer: A
Q12. Given the code fragment:
What is the result?
A. 10 8 6 4 2 0
B. 10 8 6 4 2
C. An Arithmetic Exception is thrown at runtime
D. The program goes into an infinite loop outputting: 10 8 6 4 2 0. . .
E. Compilation fails
Answer: B
Q13. The protected modifier on a Field declaration within a public class means that the field
______________.
A. Cannot be modified
B. Can be read but not written from outside the class
C. Can be read and written from this class and its subclasses only within the same
package
D. Can be read and written from this class and its subclasses defined in any package
Answer: D
Q14. Given the code fragment:
System.out.printIn ("Result: " +3+5);
System.out.printIn ("Result: " + (3+5));
What is the result?
A. Result: 8
Result: 8
B. Result: 35
Result: 8
C. Result: 8
Result: 35
D. Result: 35
Result: 35
Answer: B
Q15. 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
Q16. What is the result?
A. sc: class.Object asc: class.AnotherSampleClass
B. sc: class.SampleClass asc: class.AnotherSampleClass
C. sc: class.AnotherSampleClass asc: class.SampleClass
D. sc: class.AnotherSampleClass asc: class.AnotherSampleClass
Answer: D