Question 227 / 297:  What is the possible results of compiling and running the following code?
Choose 3
public class Test {

static Runnable t1 = new Runnable() {

public void run() {

try {

System.out.print("t1before");

Thread.sleep(100);

System.out.print("t1after");

} catch (InterruptedException e) {

}

}

};

static Thread t2 = new Thread() {

public void run() {

try {

System.out.print("t2before");

synchronized (this) {

wait();

}

System.out.print("t2after");

} catch (InterruptedException e) {

}

}

};

public static void main(String[] args) throws InterruptedException {

new Thread(t1).start();

t2.start();

}

}

<< First < Previous Next > Last >>
Explanation:

The program has no compilation errors.

Calling wait() will cause t2 to wait until another thread invokes the notify() method or the notifyAll() method for this object, which will not happen in this program and which will cause statement "t2after" not to be printed

Exam Home Page
Ask
Royalle Moore
Start Quiz
Dravida Mahadeo-J...
Start Quiz
Dionne Mahaffey
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>