Share on Google+Share on Google+

SCJP Module-8 Question-2

Advertisement
The program given below will check your concepts of Java Threads and how to used thread in Java.

Given a sample code:

1    public class Test implements Runnable {
2    public void run() {
3    System.out.println("Inside run");
4    }

5    public static void main(String[] args) {
6    // place code here.
7    // place code here.    
8    t.start();
9    System.out.println("End of main");
}}

What statement should be placed at line number 6 and 7 so that result will come as
"Inside run" 
"End of main"

Choose the correct option:

(A) Runnable r = new Runnable(); and Thread t = new Thread(r);
(B) Runnable r = new Thread(); and Thread t = new Thread(r);
(C) Runnable r = new Test(); and Thread t = new Thread(r);
(D) Runnable r = new Test(); and Thread t = new Thread(new Test);

Answer:

(C)

Advertisements

Advertisement

Posted on: July 14, 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.