Re: Why two ways (implementing Runnable,extending Thread) to create a 'thread' in java?
Monday, July 14, 2003 02:50 AM
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.
Make your thread class extend from java.lang.Thread and provide new implementations for the methods by overriding them.
Hope this is clear..