Q1. Which two are Java Exception classes?
A. SercurityException
B. DuplicatePathException
C. IllegalArgumentException
D. TooManyArgumentsException
Answer: A,C
Q2. 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: A,B
Q3. Given the code fragment:
What is the result?
A. Found Red
Found Default
B. Found Teal
C. Found Red
Found Blue
Found Teal
D. Found Red
Found Blue
Found Teal
Found Default
E. Found Default
Answer: B
Q4. Given the following main method:
What is the result?
A. 5 4 3 2 1 0
B. 5 4 3 2 1
C. 4 2 1
D. 5
E. Nothing is printed
Answer: D
Explanation:
Loop will run only once and after that num == 0 will break it After first cycle of the loop.
Q5. Which two statements are true for a two-dimensional array?
A. It is implemented as an array of the specified element type.
B. Using a row by column convention, each row of a two-dimensional array must be of the same size.
C. At declaration time, the number of elements of the array in each dimension must be specified.
D. All methods of the class Object may be invoked on the two-dimensional array.
Answer: A,D
Q6. Given the code fragment:
A. Super Sub Sub
B. Contract Contract Super
C. Compilation fails at line n1
D. Compilation fails at line n2
Answer: D
Q7. Given:
What is the result?
A. 0 Done
B. First Exception Done
C. Second Exception
D. Done Third Exception
E. Third Exception
Answer: B
Q8. Given:
Which two classes use the shape class correctly?
A. Option A
B. Option B
C. Option C
D. Option D
E. Option E
F. Option F
Answer: B,E
Explanation: When an abstract class is subclassed, the subclass usually provides implementations for all of the abstract methods in its parent class (E). However, if it does not, then the subclass must also be declared abstract (B). Note: An abstract class is a class that is declared abstract—it may or may not include abstract methods. Abstract classes cannot be instantiated, but they can be subclassed.
Q9. Given:
What is the result?
A. A B C D
B. A C D
C. A B C
D. A B D
E. A B D C
Answer: C
Q10. Given:
What is the output?
A. [21, 13, 11]
B. [30]
C. []
D. Compilation fails due to error at line 7
E. Compilation tails due to error at line 10
Answer: D
Explanation:
Option D is the correct answer.
Code fails to compile as we can't use primitive for collections type, so in this code trying to
use int at line 7, causes a compile error. We should have use wrapper. Integer there. So
option D is correct.
https://docs.oracle.eom/javase/8/docs/api/java/util/ArrayList.html