Originally posted by Sri Sri:
in class C, as we are starting thread using an instance of A, the thread method run of A is called? Is it ?
Short answer: Yes.
Long answer:
new A(new B()).start(); creates a new instance of A, passing a new instance of B to the constructor. Then the start() method of A is called. Since A did not override the start method, the start method that A inherited from Thread is called. The start method in Thread creates a new thread, and causes the new thread to execute the run method. Since A overrode the run method in Thread, A's run method is executed. That's why the output of the code you posted is A.
If you run the code that I posted, the output is AB, because of the super.run() statement that I added to A.run()
Hope that clarifies things for you.
[ February 08, 2003: Message edited by: John Paverd ]