by Dinesh Thakur Category: Multithreading

 

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

About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.



Search Content







Popular Article