KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
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(); } }
Tags (comma-separated)
Save Edits
Cancel