Java OCA OCP Practice Question 2291

Question

What will be the result of invoking the wait() method on an object without ensuring that the current thread holds the lock of the object?

Select the one correct answer.

  • (a) The code will fail to compile.
  • (b) Nothing special will happen.
  • (c) An IllegalMonitorStateException will be thrown if the wait() method is called while the current thread does not hold the lock of the object.
  • (d) The thread will be blocked until it gains the lock of the object.


(c)

Note

An IllegalMonitorStateException will be thrown if the wait() method is called when the current thread does not hold the lock of the object.




PreviousNext

Related