Home Tutorial Java Scjp Part8 SCJP Module-8 Question-6

 
 

Share on Google+Share on Google+
SCJP Module-8 Question-6
Posted on: July 15, 2010 at 12:00 AM
Advertisement
This example will check your understanding about the Thread class and their execution in Java.

Given a sample code:

1    public class Test extends Thread {

2    public static void main(String[] args) throws Exception {
3    Test t = new Test();
4    t.start();
5    t.method();
    }

6    public void run() {
7    System.out.println("run");
    }

8    public void method() {
9    System.out.println("method");
}}

Which of the following statement is correct ?

(A) Print "run method"
(B) Print "method run"
(C) Raise runtime exception
(D) Compilation error at line no 3.

Answer

(B) Print "method run"

Reason

At first the stat() method is called and this will start the thread but just after the start method the method() is called which will call the "method" and after this the run() method will be called automatically. Therefore the output is "method run".

Advertisement

Related Tags for SCJP Module-8 Question-6:


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.

Posted on: July 15, 2010

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com