In question 7 page 748, I think the answer C could be correct.
The question says only that a and b are two private variables, they're not necessarily primitives. Thanks to auto-boxing "a" could be an object of type Integer so we could synchronize on it.
SCJP 93%, SCJD 94%
Joined: Sep 17, 2006
Some of the questions in some exams not directly from Sun occasionally put harder questions in so that when you get to the Official Test, you pass the test, which is the true objective for everybody ... but when anyone says could be an object, I can be sure that I will not sync() on it. There are way too many issues in sync to let an ambiguity be the rest basis for one's design. [ November 25, 2007: Message edited by: Nicholas Jordan ]
"The differential equations that describe dynamic interactions of power generators are similar to that of the gravitational interplay among celestial bodies, which is chaotic in nature."
Originally posted by damien lepage: ...Thanks to auto-boxing "a" could be an object of type Integer so we could synchronize on it...
Welcome to JavaRanch!
That's good thinking, but if you try to verify this with some test code, I think you will find it does not work. Note that within the scope of the set method, 'a' is a local variable of type int -- it is not a reference to the instance variable 'a' of type Integer. Therefore, you will get a compilation error...
unexpected type found : int required: reference
So this would work if the block was synchronized on this.a instead of simply a. But that's not what's shown in option C.
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer sscce.org
Joined: Nov 25, 2007
Thanks Marc. You're right, I missed this shadowing.