106k views
4 votes
What is the signature of the wait() method in Java?

1) public void wait(long timeout)
2) public final void wait(long timeout)
3) public synchronized void wait(long timeout)
4) public final synchronized void wait(long timeout)

User Kathrice
by
8.3k points

1 Answer

2 votes

Final answer:

The signature of the wait() method in Java is 'public final void wait(long timeout) throws InterruptedException', and it is used to make a thread wait for another thread's notification or for a specified timeout.

Step-by-step explanation:

The correct signature for the wait() method in Java is public final void wait(long timeout) throws InterruptedException. The wait() method is defined in the Object class, and all objects in Java inherit this method. It is used to make the current thread wait until another thread calls notify() or notifyAll() on the same object or until the specified timeout expires. Furthermore, wait() is always called within a synchronized context, that is, within a synchronized method or block. It's also important to notice that it throws an InterruptedException, which is a checked exception that must be either caught or declared to be thrown in the method that calls wait().

User Mario Petrovic
by
8.1k points