Share on Google+Share on Google+

SCJP Module-8 Question-7

Advertisement
The Sample program given below will check your knowledge about the Runnable interface Thread class in Java.

Given a sample code:

public class Test implements Runnable {
public void run() {
System.out.print("run");
}

public static void main(String[] args) {
Runnable r = new Test();
Thread t = new Thread(r);
t.run();
t.start();
t.run();
}
}

Which of the following statement is correct ?

(A) Compilation fails.
(B) Print "run run run"
(C) An exception is thrown at runtime.
(D) Print "run"

Answer:

(B)

Advertisements

Posted on: July 15, 2010 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.