Exam Permalink:
https://www.jobilize.com/java-certification-questions
Question Permalink:
https://www.jobilize.com/run-vs-start-in-threads-in-java
Question 223 / 297:  What are the possible results of compiling and running the following code?
Choose 2
public class Test implements Runnable {

int id;

Test(int id) {

this.id = id;

}

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

Thread thread1 = new Thread(new Test(1));

Thread thread2 = new Thread(new Test(2));

thread1.run();

thread2.start();

System.out.print("main");

}

public void run() {

System.out.print(id);

}

}

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

Invoking run() on a thread doesn't cause a new thread of execution to start with a new call stack, invoking method start() does that. Therefore line thread1.run() will always execute and complete executing before thread2.start()

Exam Home Page
https://www.jobilize.com/java-certification-questions

Oracle Certified Professional Java Programmer

Author:

Access: Public Instant Grading

Ask
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>