Thread class implements Runnable interface. So when we wxtend Thread class Run() must be defined.
Following code sample is taken from mocktest in another section. In this code, run() is not implemented. Is not that a compile time error ? When I read the answer, it says code will run fine, but will not print anything.
Thread implements run(), but does nothing.
When extending classes, you don't have to implement their methods. You may overwrite them, but you don't have to. So a call to the run() method of a Bground object will call Thread's implementation of run(), which simply does nothing.
Life is full of choices. Sometimes you make the good ones, and sometimes you have to kill all the witnesses.
Jan Hoppmann wrote:Thread implements run(), but does nothing.
Actually it does something. If you create a Thread with a Runnable as argument to the constructor, it will call run() on that Runnable. If you don't provide a Runnable then it does nothing. Part of the source code for Thread, taken from src.zip:
I think nirjari's question is whether extending the Thread class implies having to implement the run() method. This is not the case, your extended class inherits the run() method which is already in the Thread class. I think you confuse the 2 ways of defining a thread:
1) Extend the Thread class and override the run() method.
2) Implement the Runnable interface and implement the run() method.