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!");
}
}

