by Dinesh Thakur

 

class InheritanceMethod extends Thread

       {
           InheritanceMethod(String n)
               {
               super(n);
               System.out.println("Thread is :"+getName());
               }
                  public void run()
                      {
                      try
                       {
                          for(int i=1;i<=5;i++)
                          {
                             System.out.println(getName()+":"+i);
                             sleep(500);
                          }
                            }
                                    catch(InterruptedException e)
                                   {
                                     System.out.println(getName()+" is Interupted");
                                   }
                     }
        }
                      class MultipleThreadsInheritance
                         {
                             public static void main(String args[])
                               {
                               InheritanceMethod t1=new InheritanceMethod("AWT Thread");
                           InheritanceMethod t2=new InheritanceMethod("Swing Thread");
                           t1.start();
                           t2.start();
                           }
                        }

Multiple Threads in Java by Inheritance