Q21. Given: 

What will be the output? 

A. Option A 

B. Option B 

C. Option C 

D. Option D 

Answer:


Q22. Given: 

What is the result? 

A. hEllOjAvA! 

B. Hello java! 

C. Out of limits hEllOjAvA! 

D. Out of limits 

Answer:


Q23. Which of the following exception will be thrown due to the statement given here? 

int array[] = new int[-2]; 

A. NullPointerException 

B. NegativeArraySizeException 

C. ArrayIndexOutOfBoundsException 

D. IndexOutOfBoundsException 

E. This statement does not cause any exception. 

Answer:

Explanation: 

In given statement we can see that, we have passed negative value for creating int array, 

which results a NegativeArraySize Except ion. Hence option B is correct. 

Option A is incorrect as it is thrown when an application attempts to use null in a case 

where an object is required. 

Option D is incorrect as IndexOutOfBoundsException thrown to indicate that an index of 

some sort (such as to an array, to a string, or to a vector) is out of range. 

REFERENCE 

rhttpy/docs.oracle.com/iavase/S/docs/api/java/lang/NegativeArraySizeException.html 


Q24. Given: 

Which of the following is equivalent to the above code fragment? 

A. System.out.printLn(x>10?">,': "<":,'="); 

B. System.out.println(x>10? ">"?"<":"="); 

C. System.out.println(x>10?">":x<10?"<":"="); 

D. System.out.printLn(x>10?">"?,'<"?"="); 

E. None of the above 

Answer:

Explanation: 

Option A is incorrect as we can't use abstract with non abstract method, (here method has method body.) Option C is incorrect as when overriding method we can't use more restrictive access modifier, so trying to use private to override default access Level method causes a compile time error. Option D is incorrect as default methods (not methods with default access level) are allowed only in interfaces. Option E is incorrect as method all ready has void as return type, so we can't add int there. Option B is correct as we can use final there, since the method is non abstract 

https://docs.oracle.com/javase/tutorial/java/landl/polymorphism.html 


Q25. Given: 

Which code fragment should you use at line n1 to instantiate the dvd object successfully? 

A. Option A 

B. Option B 

C. Option C 

D. Option D 

Answer:


Q26. Given: 

How many objects have been created when the line / / do complex stuff is reached? 

A. Two 

B. Three 

C. Four 

D. Six 

Answer:


Q27. Given the code fragment: 

What is the result? 

A. May 04, 2014T00:00:00.000 

B. 2014-05-04T00:00: 00. 000 

C. 5/4/14T00:00:00.000 

D. An exception is thrown at runtime. 

Answer:

Explanation: 

java.time.temporal.UnsupportedTemporalTypeException: Unsupported field: HourOfDay 


Q28. Given the code format: 

Which code fragment must be inserted at line 6 to enable the code to compile? 

A. DBConfiguration f; return f; 

B. Return DBConfiguration; 

C. Return new DBConfiguration; 

D. Retutn 0; 

Answer:


Q29. public class StringReplace { 

public static void main(String[] args) { 

String message = "Hi everyone!"; 

System.out.println("message = " + message.replace("e", "X")); } 

What is the result? 

A. message = Hi everyone! 

B. message = Hi XvXryonX! 

C. A compile time error is produced. 

D. A runtime error is produced. 

E. message = 

F. message = Hi Xveryone! 

Answer:


Q30. Given: 

Class A { } 

Class B { } 

Interface X { } 

Interface Y { } 

Which two definitions of class C are valid? 

A. Class C extends A implements X { } 

B. Class C implements Y extends B { } 

C. Class C extends A, B { } 

D. Class C implements X, Y extends B { } 

E. Class C extends B implements X, Y { } 

Answer: A,E 

Explanation: extends is for extending a class. 

implements is for implementing an interface. Java allows for a class to implement many interfaces.