Discussion :: Threads
-
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(); } }
Answer : Option B
Explanation :
The program will execute without any problems and print 12 12 12 12.
Be The First To Comment