Create a class which extends a Thread Class. 2. Override run()

class NewThread extends Thread
{
 NewThread()
 {
  setPriority(Thread.MIN_PRIORITY);
  start();
 }
 public void run()
 {
  try
  {
   for(int i = 5; i>0;i--)
   {
    System.out.println("Child Thread 1 : " +i);
    Thread.sleep(100);
   }
  }
  catch (InterruptedException e)
  {}
 }
}
class NewThread1 extends Thread
{
 NewThread1()
 {
  setPriority(Thread.MAX_PRIORITY);
  start();
 }
 public void run()
 {
  try
  {
   for(int i = 10; i>5;i--)
   {
    System.out.println("Child Thread 2 : " +i);
    Thread.sleep(100);
   }
  }
  catch (InterruptedException e)
  {}
 }
}
class  Exp9_3
{
 public static void main(String[] args) 
 {
  new NewThread();
  new NewThread1();
 }
}
/*  OUTPUT!!!
Child Thread 1 : 5
Child Thread 2 : 10
Child Thread 1 : 4
Child Thread 2 : 9
Child Thread 1 : 3
Child Thread 2 : 8
Child Thread 1 : 2
Child Thread 2 : 7
Child Thread 1 : 1
Child Thread 2 : 6
*/

Copyright © LetML. Blogger Templates Designed by OddThemes