The given code speaks loudly that the exception, that will be thrown is
IllegalMonitorStateException. That is because, wait() method is called in
the synchronized context; you first take lock of that object and then call
wait method inside that block, and then release the lock.
Alright,
Vasilli & Megha, you agree upto this?
I am only concerned about the question (picked from a reputed mock exam),
It has several options and the given correct answer says IllegalStateException; There is no corelation between IllegalMonitorStateException and IllegalStateException;
As I know the IllegalThreadStateException is thrown when you call start() method on the thread more than once.
IllegalStateException is thrown when you call a method on scanner reference
when it is closed.
java.util.Scanner scan = new java.util.Scanner(System.in);
scan.nextInt();
scan.close();
scan.nextInt(); //IllegalStateException
But I am afraid of the bizarre answer of the original question posted by me on the top, regarding IllegalStateException.
Megha says,
I think synchronized() can take a Thread object as argument.
Definitely synchronized() can take Thread object; It means no more than
one thread can access that object at a time; I think this scenario in the
following way:
Thanks,
cmbhatt
[ April 25, 2007: Message edited by: Chandra Bhatt ]