Threads

Q1: 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(); 
    } 
}

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...

ANS:A - Compile time Error There is no start() method

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



img not found
img

For help Students Orientation
Mcqs Questions

One stop destination for examination, preparation, recruitment, and more. Specially designed online test to solve all your preparation worries. Go wherever you want to and practice whenever you want, using the online test platform.