posted 19 years ago
In class C,
new Thread(new B(),"T1").start();
starts a new thread named T1, and this start invokes run method of
class B.
class B's run method is :
new A().run(); <== call class A's run method
<== and class A's run method prints the
<== name of current executing thread
<== and currently executing thread is T1
new Thread(new A(),"T2").run();
<== This statement is creating a new Thread
<== and calling run method of Thread directly
<== Note : run method called in this statement
<== none of the run methods coded here, but
<== the one coded in java.lang.Thread and
<== which calls the run method of Runnable
<== passed in the constructor and this is
<== A's run method. ( This statement calls
<== run method directly so no new thread
<== is spawned in statement. ) So, A's run
<== method still prints T1 as that is the only
<== thread still executing, so T1 is printed
<== again
new Thread(new A(),"T3").start();
<== This spawns a new thread named T3 and by now
<== it should be clear why T3 is printed
Hope this clarifies the confusion.