This is from Enthuware (QID: com.enthuware.ets.scjp.v6.2.388).
I answered d because I thought that the code won't even compile because the instance method
run is accessing the static variables x and y. My answer is correct but my thoughts didn't match the explanation:
You may be tempted by the synchronized keyword on the run method. But note that, there are two diferent thread objects and both the threads are accquiring locks for their own thread object. So, in this case synchronized doesn't make any sense.
I tried to compile and run the program, and it worked. I'm confused here, how come the static variables x and y were accessed successfully in the run method, which is an instance method? Or am I just seeing it the wrong way?
[ September 08, 2008: Message edited by: Denise Saulon ]