java thread - run() and start() methods

Posted by JavaUser on Stack Overflow See other posts from Stack Overflow or by JavaUser
Published on 2010-06-12T04:32:14Z Indexed on 2010/06/12 4:42 UTC
Read the original article Hit count: 251

Filed under:
|

Please explain the output of the below code:

If I call th1.run() ,the output is

     EXTENDS RUN>>
     RUNNABLE RUN >>

If I call th1.start() , the output is :

    RUNNABLE RUN >>
    EXTENDS RUN>>

Why this inconsistency . Please explain.

class ThreadExample extends Thread{

public void run(){
    System.out.println("EXTENDS RUN>>");
}

}

class ThreadExampleRunnable implements Runnable {

public void run(){
    System.out.println("RUNNABLE RUN >>");
}
}

class ThreadExampleMain{

public static void main(String[] args){

    ThreadExample th1 = new ThreadExample();
    //th1.start(); 
    th1.run();


    ThreadExampleRunnable th2 = new ThreadExampleRunnable();
    th2.run();
}
}

© Stack Overflow or respective owner

Related posts about java

Related posts about multithreading