Home » Java Programming » 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(); } }

Correct Answer: It print 12 12 12 12

Explanation:

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

← Previous Question Next Question→

More Questions from Threads

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion