What happens if a Java thread calls obj.wait() without owning the monitor of obj?
Correct answer D. An IllegalMonitorStateException is thrown
Explanation
The wait, notify and notifyAll methods require the calling thread to hold the object's monitor, normally by being inside a synchronized block on that object. Violating this cannot be detected by the compiler in general, so the JVM throws IllegalMonitorStateException at run time. Wait should also be called in a loop that rechecks its condition.
Answer checked How we write and check questions
Discussion