This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
mythread.start() The above statement is not starting the new thread.It just calls the overridden start() method in MyThread class.
Thats why you got the output : MyThread: start()
thread.start(); This statement starts the newly created thread.This will access start() method declared in Thread class which in turn calls run() method declared in MyRunnable class which results in the output MyRunnable: run()
mythread.start() calls the start() of MyThread alone thread.start() calls the start() of Thread class which calls run() of MyRunnable.
Originally posted by dolly shah: I got the output. But I have another question. Why MyRunnable class is able to implement start() method. It is not a Runnable interface method. can you explain?
For the same reason the MyRunnable class is able to implement a method named join(), alive(), hello(), goodbye(), mymethod1(), mymethod2(), etc. Just because you implement an interface, doesn't mean that you are not allowed to have methods that is not part of that interface.