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.
Thanks
Damien
Damien Lepage
SCJP 93%, SCJD 94%
Nicholas Jordan
Ranch Hand
Joined: Sep 17, 2006
Posts: 1282
posted
0
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
damien lepage
Greenhorn
Joined: Nov 25, 2007
Posts: 7
posted
0
Thanks Marc. You're right, I missed this shadowing.
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.