Re: Why two ways (implementing Runnable,extending Thread) to create a 'thread' in java?
Posted By:
Anonymous
Posted On:
Monday, July 14, 2003 02:50 AM
Hi Srinivasan,
Option 1:
Runnable Interface
Runnable interface has only one method declared in it. So if you choose this option, just make your thread class implement this interface and provide the implementation for the run method.
Thread runnableT = new Thread(myClassEWithRunnable);
So, here 'runanbleT' will have all the methods from the java.lang.Thread class + the run() method you we wrote in the thread class.
But, what if we would want to change the default implementation for one of the methods that come from the Thread class? With the first option you cannot... To do this, the second option is given.
Option 2:
Make your thread class extend from java.lang.Thread and provide new implementations for the methods by overriding them.
Hope this is clear..
Satish