Exam Permalink:
https://www.jobilize.com/java-certification-questions
Question Permalink:
https://www.jobilize.com/instatiate-a-thread-by-implementing-runnable-interface
Question 170 / 297:  How many times the statement "we are painting" would be printed in this program?
public class Test{

public static void main(String[] args) {

Painter painter1 = new Painter();

painter1.start();

Painter painter2 = new Painter();

painter2.start();

}

}

class Painter implements Runnable {

public void run() {

System.out.println("we are painting");

}

}

A  two times
B  zero times
C  the program will not compile
<< First < Previous Next > Last >>
Explanation:

Instantiating from a class that implements Runnable is not enough to create a Thread object. You still to create a Thread object need to invoke a Thread constructor passing to it this Runnable object. Therefore invoking start() on a Runnable object is incorrect and causes compilation error.

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>