This week's book giveaway is in the Mac OS forum. We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line! See this thread for details.
A) Compile time Error There is no start method B) Will print in this order 11 22 33 C) Will print but not exactly in an order (eg: 123124 3) D) Will print in this order 12 3123 E) Will print in this order 123. The answer is C) why? or the answer is wrong? I ran it in JDK 1.2.2 for tons of times, the result is 11 22 33 ... 2020 Who can explain how t1 & t2 run? Thanks! -Li Jishan
In your code above, the methods addX() and addY() are not synchronized, therefore they can be executed by more than one thread at a time. Only when you synchronize the methods you can guarantee that it will give the same result everytime it runs. Also remember that thread scheduler, is platform dependant, therefore you can see the same output on your machine everytime you run the program, but if you move to another OS, you may get different result. that's why answer C is correct. hope that helps! I think answer C should be re-worded as Will print but not necessarily in an order (eg: 123124 3) [ July 28, 2002: Message edited by: Amir Ghahrai ]