Hello,
Can anyone please answer this:
Thread is a class which implements the runnable interface, so we override the run() method when we extend the Thread class and then call the start() method to actually run the thread. If I dont call the start() method and directly call run(), it will still execute ( without any "thread-ness" ). This part is perfectly clear to me. I overrode the run() method of the Thread class, so if the Thread instance calls - run(), it will execute the run() method that I defined.
Thread t1 = new MyThread() ; // Here, Thread is the superclass and its reference variable is pointing to a subclass - MyThread and calling its run method.
This is fine, as a proper linkage is established.
Now...
In case of implementing Runnable, I would pass the Runnable object to the Thread object's constructor and I am still able to call the run() method
directly on the Thread instance.
How is the linkage established in the second case. How am I able to call run() directly using the Thread's instance ?
The answer to this question might be very simple... but am not able to think of it right now :-)
Please Help.