Home / Java Programming / Threads :: Discussion

Discussion :: Threads

  1. What will be the output of the program?

     class s implements Runnable 
     {   
         int x, y;  
         public void run()    
         {     
             for(int i = 0; i 1000; i++)                
                synchronized(this)              
                {         
                    x = 12;         
                    y = 12;        
                }       
             System.out.print(x + " " + y +");     
        }   
        public static void main(String args[])       
        {    
              s run = new s();  
              Thread t1 = new Thread(run);          
              Thread t2 = new Thread(run);          
              t1.start();     
              t2.start();   
        } 
     } 
    

     

  2. A.

    DeadLock

    B.

    It print 12 12 12 12

    C.

    Compilation Error

    D.

    Cannot determine output.

    View Answer

    Workspace

    Answer : Option B

    Explanation :

    The program will execute without any problems and print 12 12 12 12.


Be The First To Comment