Sail E0 Webinar
Question


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();
}
}
Options:
A .  DeadLock
B .  It print 12 12 12 12
C .  Compilation Error
D .  Cannot determine output.
Answer: Option B

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


Was this answer helpful ?
Next Question

Submit Solution

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

Latest Videos

Latest Test Papers