Java Program to implement Thread



class   A     extends   
Thread                                                                        


      {


                public  void 
run( )                                                                           


                    {


                                for(  int i = 1 ;  
i <= 5  ;    i++  
)


                                                 System.out.println( "   From thread A :  i 
=   "  +  
i  ) ;


                                 System.out.println( " End of thread
A  " 
)  ;


                     }


       }





class    B    extends    
Thread                                                                       


      {


                public  void 
run( )                                                                           


                    {


                                for(  int j = 1 ;  
j <= 5  ;   j++ )


                                                 System.out.println(   "  
From thread B :    j =   "    
+   j   );


                                 System.out.println(  "  
End of thread B   "  )  ;


                      }


      }





class   C   extends   
Thread                                                                          


    {


                public  void 
run( )                                                                           


                    {


                                for(   int  
k = 1   ;    k 
<= 5  ;    k++ 
)


                                                 System.out.println(  " 
From thread C :     k  =  
"    +    k  );


                                 System.out.println(  "  
End of thread C    "   ) ;


                     }


     }








class   ThreadTest


                    {


                                public  static 
void  main (  String  
args[ ] )


                                    {


                                                A    obA  
=    new     A( ) ;               //
new born state


                                                obA.start(
) ;                                      //
runnable state


                               


                                                new   B( ).start( );                            





                                                new   C( ).start( );





                                System.out.println(  " 
End of main thread   "   ) ;


                                      }




                      }


Comments

Popular posts from this blog

Write a Program to Add two 3x3 Matrix using C

C program for Unit Conversion

Write a Program to Add two 5x5 Matrix using C