class NewThread implements Runnable{ Thread t; NewThread(){ t = new Thread(this,"Demo Thread"); System.out.println("child thread"+t); t.start(); } public void run(){ System.out.println("begin child"); try{ for(int i=5;i>0;i--){ System.out.println("child Thread:"+i); Thread.sleep(50); } }catch(InterruptedException e){ System.out.println("child interrupted"); } System.out.println("end child");
} } public class test {
public static void main(String[] args){ // TODO Auto-generated method stub NewThread ob = new NewThread(); System.out.println("main is :"+ob.t.isAlive()); try{ ob.t.join(); }catch(InterruptedException e){ System.out.println("main interrupted"); } System.out.println("main is :"+ob.t.isAlive()); }