Correct Answer: Will print in this order: x = 1 y = 1 x = 2 y = 2 x = 3 y = 3 x = 4 y = 4 x = 5 y = 5... but the output will be produced by first one thread then the other. This is guaranteed by the synchronised code.
Explanation:
System.out.println(Thread.currentThread().getName() + " x = " + x + ", y = " + y);
Discussion & Comments