8
Q:

void waitForSignal() {

Object obj = new Object();

synchronized (Thread.currentThread()) {

obj.wait();

obj.notify();

}

}

Which statement is true?

A) This code can throw an InterruptedException. B) This code can throw an IllegalMonitorStateException.
C) This code can throw a TimeoutException after ten minutes D) All the above

Answer:   B) This code can throw an IllegalMonitorStateException.



Explanation:

It will throw  IllegalMonitorStateException.

Subject: Java
Job Role: IT Trainer
Q:

When will you define a method as static?

Answer When a method needs to be accessed even before the creation of the object of the class then we should declare the method as static.
Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 3701
Q:

What are the restriction imposed on a static method or a static block of code?

Answer A static method should not refer to instance variables without creating an instance and cannot use "this" operator to refer the instance.
Report Error

View answer Workspace Report Error Discuss

Subject: Java

5 6577
Q:

I want to print "Hello" even before main() is executed. How will you acheive that?

Answer Print the statement inside a static block of code. Static blocks get executed when the class gets loaded into the memory and even before the creation of an object. Hence it will be executed before the main() method. And it will be executed only once.
Report Error

View answer Workspace Report Error Discuss

Subject: Java

6 7978
Q:

I do not want my class to be inherited by any other class. What should i do?

Answer You should declared your class as final. But you can't define your class as final, if it is an abstract class. A class declared as final can't be extended by any other class.
Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 2147
Q:

What is the impact of declaring a method as final?

Answer A method declared as final can't be overridden. A sub-class can't have the same method signature with a different implementation.
Report Error

View answer Workspace Report Error Discuss

Subject: Java

1 3052
Q:

What is the purpose of declaring a variable as final?

Answer A final variable's value can't be changed. final variables should be initialized before using them.
Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 2333
Q:

What is the access scope of a protected method?

Answer A protected method can be accessed by the classes within the same package or by the subclasses of the class in any package.
Report Error

View answer Workspace Report Error Discuss

Subject: Java

1 5495
Q:

Can a class be declared as protected?

Answer A class can't be declared as protected. only methods can be declared as protected.
Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 2196