Julian,
Thank you for using my exam.
The following are all of the answer options for the question.
What are the possible results of attempting to compile and run the program?
a. Prints: X0Y1X2Y3X4Y5.
b. Prints: X0X1X2Y3Y4Y5.
c. Prints: X0Y0X1Y1X2Y2.
d. Prints: X0X1X2Y0Y1Y2.
e. Compiler error.
f. Run time error.
g. None of the above.
Since the method is synchronized we know that the value returned by the method will be unique. In other words, both threads will never read the same value. Therefore, answer options c and d can be eliminated. Both answer options 'a' and 'b' are possible because the thread scheduler could allow the two threads to run in any order.
The behavior of the Thread.yield method is platform dependent. There is no guarantee that Thread.yield will cause the running thread to allow a different thread to run.
This is really not a question about the Thread.yield method. I just put it in there so that if you run the program you will be more likely to see a wider variety of results.
The real exam does not emphasize the Thread.yield method. Just remember that the behavior is platform dependent.