Originally posted by Alan Chong:
<<<It inserts a statement " rrr.run();"
WHAT!?!
I really don't follow your explanation. The compiler surely isn't going to start throwing code into your program for you. Here, I've modified the original code slightly:
This program is designed to print something depending on which run method is invoked. As it is, only "T" gets printed. Therefore, the Runnable object is ignored and the run method in it is never called.
Now, had I modified the program to explcitly invoke the run method of the Runnable object (as you did in your second example), of course the run method will be invoked. But, it's not being invoked automatically by a thread, you're invoking explicitly just like any other method.
Both run methods
do not get invoked. Not unless, you code it to do so. The trick to the problem, as Val stated, is to understand which run method will be invoked.
Also, on a sidenote - if you're going to post code in your message, please use
code tags. It will make the code much more readable.
Corey