Placement papers on Java - Set 5

Placement papers on Java - Set 5


1. In Java, an abstract class cannot be sub-classed.

TRUE
FALSE
View Answer / Hide Answer

ANSWER: FALSE




2. Which of these statements are not legal. Select the correct answers.

int arr[][] = new int[5][5];
int[]arr[] = new int[5][5];
int[] arr = new int[5][];
int[] arr = new int[][5];
View Answer / Hide Answer

ANSWER: int[] arr = new int[][5];




3. What happens when the following code is compiled and run. Select the one correct answer.

for(int i = 1; i < 3; i++)
for(int j = 3; j >= 1; j--)
assert i!=j : i;"

The class compiles and runs, but does not print anything.
The number 1 gets printed with AssertionError
The number 2 gets printed with AssertionError
The number 3 gets printed with AssertionError
View Answer / Hide Answer

ANSWER: The number 1 gets printed with AssertionError




4. Which is true about an anonymous inner class?

It can extend exactly one class and implement exactly one interface.
It can extend exactly one class and can implement multiple interfaces.
It can implement multiple interfaces regardless of whether it also extends a class.
View Answer / Hide Answer

ANSWER: It can extend exactly one class and can implement multiple interfaces.




5. Which is true about a method-local inner class?

It must be marked final.
It can be marked abstract.
It can be marked public.
It can be marked static.
View Answer / Hide Answer

ANSWER: It can be marked abstract.




6. Which statement is true about a static nested class?

You must have a reference to an instance of the enclosing class in order to instantiate it.
It does not have access to nonstatic members of the enclosing class.
It's variables and methods must be static.
It must extend the enclosing class.
View Answer / Hide Answer

ANSWER: It does not have access to nonstatic members of the enclosing class.




7. Which constructs an anonymous inner class instance?

Runnable r = new Runnable() { };
Runnable r = new Runnable(public void run() { });
Runnable r = new Runnable { public void run(){}};
System.out.println(new Runnable() {public void run() { }});
View Answer / Hide Answer

ANSWER: System.out.println(new Runnable() {public void run() { }});




8. What is the value of "d" after this line of code has been executed?
double d = Math.round ( 2.5 + Math.random() );

2
3
4
2.5
View Answer / Hide Answer

ANSWER: 3




9. Which of the following would compile without error?

int a = Math.abs(-5);
int b = Math.abs(5.0);
int c = Math.abs(5.5F);
int d = Math.abs(5L);
View Answer / Hide Answer

ANSWER: int a = Math.abs(-5);




10. What allows the programmer to destroy an object x?

x.delete()
x.finalize()
Runtime.getRuntime().gc()
Only the garbage collection system can destroy an object.
View Answer / Hide Answer

ANSWER: Only the garbage collection system can destroy an object.



Post your comment