SCJP Module-8 Question-2


 

SCJP Module-8 Question-2

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

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)

Ads