import java.io.*;
class NewThread extends Thread
{ NewThread()
{ super("Demo Thread");
System.out.println("child thread: "+this);
start();
}
public void run()
{ try
{ for(int i=5;i>0;i--)
{ System.out.println("child thread: " + i);
Thread.sleep(500);
}
}catch(Exception e){}
System.out.println("Exiting child thread");
}
}
class thread2
{ public static void main(String args[])
{ NewThread obj=new NewThread();
try
{ for(int i=5;i>0;i--)
{ System.out.println(" Main thread: " +i);
Thread.sleep(1000);
}
}catch(Exception e){}
System.out.println("Exiting Main Thread");
}
}
Comments
Post a Comment