Question 91 / 297:  What is the result of compiling and running the following program?
public class Tester {

public void validate() {

int i = 0;

while (++i < 3) {

try {

wait();

} catch (InterruptedException e) {

e.printStackTrace();

}

System.out.print(i);

}

}

public static void main(String[] args) {

new Tester().validate();

}

}

A  Compilation error because of calling wait() outside a synchronized block
B  Compilation error because IllegalMonitorStateException is not handled
C  At runtime, it throws an IllegalMonitorStateException when trying to wait
D  12
<< First < Previous Next > Last >>
Explanation:

If the thread calling wait() does not own the lock on the object, a IllegalMonitorStateException will be thrown.

Exam Home Page
Ask
Keyaira Braxton
Start Exam
Hope Percle
Start Quiz
Copy and paste the following HTML code into your website or blog.
<iframe src="https://www.jobilize.com/embed/java-certification-questions" width="600" height="600" frameborder="0" marginwidth="0" marginheight="0" scrolling="yes" style="border:1px solid #CCC; border-width:1px 1px 0; margin-bottom:5px" allowfullscreen webkitallowfullscreen mozallowfullscreen> </iframe>