Home / Java Programming / Threads :: Discussion

Discussion :: Threads

  1. What will be the output of the program?

     class s1 extends Thread
     {   
        public void run()     
        {         
           for(int i = 0; i 3; i++)        
           {
                System.out.println("A");                  
                system.out.println("B");          
           }    
        }  
    } 
     class Test120 extends Thread  
    {    
      public void run() 
      {     
         for(int i = 0; i 3; i++)   
         {              
                System.out.println("C");              
                System.out.println("D");             
          }    
       }   
       public static void main(String args[])                 
          {       
          s1 t1 = new s1();   
          Test120 t2 = new Test120();          
          t1.start();     
          t2.start();     
       }  
    } 

     

  2. A.

    Compile time Error There is no start() method

    B.

    Will print in this order AB CD AB...

    C.

    Will print but not be able to predict the Order

    D.

    Will print in this order ABCD...ABCD...

    View Answer

    Workspace

    Answer : Option C

    Explanation :

    We cannot predict the order in which threads are going to run.


Be The First To Comment