class MyThread extends Thread{
public void run(){
// print child thread 5 times here
for(int i =0 ; i<=5 ; i++){
System.out.println("child Thread....");
}
}
}
//main method class which is main thread here
class JoinDemo{
public static void main(String args[]){
// this is main thread
// print main thread here
// create thread
MyThread t = new MyThread();
t.start(); // start child thread here
try{
t.join();// pause main thread here and after complete t resume current thread
}catch(Exception e){
System.out.println("Exception caught "+e);
}
for(int i =0 ; i<=5 ; i++){
System.out.println(" Main Thread....");
}
}
}