Java_Labprogram_12
Java_Labprogram_12
constructor, using super and start the thread. The run method of the class starts after this. It can
be observed that both main thread and created child thread are executed concurrently.
Solution:-
try
Thread.sleep (1000);
catch (InterruptedException e)
}
System.out.println (getName () + " exiting.");
try
Thread.sleep (2000);
catch (InterruptedException e)
}
Compile As: javacThreadConstructor.java
Output:
Main Thread: 5
Child Thread: 5
Child Thread: 4
Main Thread: 4
Child Thread: 3
Child Thread: 2
Main Thread: 3
Child Thread: 1
Main Thread: 2
Main Thread: 1