Saturday, 5 September 2015

S8P2

Write the thread program using Runnable interface.

Code:
 class MyThread implements Runnable  
 {  
      public void run()  
      {  
           for(int i=0; i<10; i++)  
           {  
                System.out.println("NewThread: "+(i+1));  
           }  
           System.out.println("End of NewThread");  
      }  
 }  
 class S8P2_Runnable  
 {  
      public static void main(String args[])  
      {  
           MyThread runn = new MyThread();  
           Thread NewThread = new Thread(runn);  
           NewThread.start();  
           System.out.println("\nEnd of main Thread");  
      }  
 }  


Output:


No comments:

Post a Comment