Java Programming - Overriding the start() method in Thread

In the following code, the start() method of Thread class has been overridden.

The code compiles and runs successfully (although we know that nothread has been created).

How can it be proved that this code does not create a new thread?

publicclass OverridingStartMethodextends Thread

{

publicvoid start()

{

System.out.println("Overrriden start() called!");

this.run();//explicit call to run()

}

publicvoid run()

{

System.out.println("Inside child thread!");

try

{

Thread.sleep(5000);

}

catch(InterruptedException ex)

{

ex.printStackTrace();

}

}

publicstaticvoid main(String args[])

{

Thread t =new OverridingStartMethod();

System.out.println("Parent thread started!");

t.start();

try

{

t.join();

}

catch(InterruptedException ex)

{

ex.printStackTrace();

}

System.out.println("Parent thread: Child thread terminated!");

}

}

[2218 byte] By [nitin.gaura] at [2007-11-26 23:18:38]
# 1
Simply store the reference in Thread.currentThread() at the start of your program and compare it against the value of currentThead in the run() method.
malcolmmca at 2007-7-10 14:20:50 > top of Java-index,Java Essentials,Java Programming...