Sail E0 Webinar
Question


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();
}
}
Options:
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...
Answer: Option C

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



Was this answer helpful ?
Next Question

Submit Solution

Your email address will not be published. Required fields are marked *

Latest Videos

Latest Test Papers