6
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:

What is anonymous class?

Answer

Anonymous class is class without name.


EX:


class A {


}


class Demo {


    A r = new A() {


        }; //anonymous class


}


 

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 1656
Q:

What is local class?

Answer

Local class is class defined inside method


EX;


class A { // top level class


  public static void main(string[] args) {


   class B { // local class


   }


}


}

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 1757
Q:

what is non-static member class?

Answer

Non-static member class is a class defined inside outer class with out static modifier.


EX:


class A { // top level class or outer class


    ......


    class B { //non-static member class


    }


    .....


}

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 1620
Q:

What is static member class?

Answer

Static member class is a class defined inside outer class with static modifier.


EX:


Class A {  //top level class or outer class


    .....


    static class B {  //static member class


    }


   .....


}

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 1818
Q:

What is top level class?

Answer

Top level class is also called outer class. It is not defined inside any class.


Ex:


class A {  //top level class


 


}

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 1686
Q:

How many types of classes are there in Java?

Answer

Two types of classes:


1) Top Level Class


2) Classes within Class


       i) member classes


             a) static member class


             b) non static member class


      ii) local classes


      iii) anonymous classes

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 1701
Q:

What is the purpose of the wait(), notify(), and notifyAll() methods ?

Answer

The wait(), notify(), and notifyAll() methods are used to provide an efficient way for threads to wait for a shared resource. When a thread executes an object's wait() method, it enters the waiting state. It only enters the ready state after another thread invokes the object's notify() or notifyAll() methods..

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 1720
Q:

What are wrapped classes ?

Answer

Wrapped classes are classes that allow primitive types to be accessed as objects.

Report Error

View answer Workspace Report Error Discuss

Subject: Java

0 1736