The explanation isD. Four objects are eligible for garbage collection.
D is correct because only one Account object is created, and a1, a2, and a3 all refer to it. The Account object has two Long objects associated with it, and finally the anonymous Banker object is also eligible.
OCPJP 6 96%
Stephan van Hulst wrote:I think you are onto something here. As far as I can tell, you are correct.
Note that there's also a String created, but it won't be collected because it goes to the String pool.
OCPJP 6 96%
micha koern wrote:Difficult question. I thought the Wrapper also has a pool (therefore the Method valueOf).
Only when new is called a new Object is created if not its up to the Wrapper to use the pool or create something new.
OCPJP 6 96%
micha koern wrote:Oh Right!
Try this:
The output is false, so there is really a new Object- i agree 5 Objects are eligible.
OCPJP 6 96%
Roel De Nijs wrote:
It's true that a total of 5 objects are created, but when reaching line 5 just 4 will be eligible for garbage collection (because 1 of the created objects became already eligible on another time, so this object could already be garbage collected when reaching line 5).
OCPJP 6 96%
Spot false dilemmas now, ask me how!
(If you're not on the edge, you're taking up too much room.)
Francisco J. Bermejo wrote:Until now I simply assumed (wrongly) that in this kind of questions the garbage collector did not run until the asked line is reached.
"Only one CardBoard object (c1) is eligible, but it has an associated Short wrapper object that is also eligible."
OCPJP 6 96%
Stephan van Hulst wrote:The object referenced by c2 is still reachable (through c2).
OCPJP 6 96%
Milind Vaishnaw wrote:How could we create 3 Long objects for one Account object???
Milind Vaishnaw wrote:Hi all ,
i think the answer given by book is correct. For an Account object here , we can create only 2 Long objects.
Declared as
class Account{
Long acctNum;
Long password;
}
The one and only password(Long) object is initialized first time as
a3.password = a1.acctNum.LongValue();
and then
a2.password = 4455L;
here all a1.password , a2.password and a3.password refers to same Long object of Account object.
I think there is no significance of line 12 because a1.password( a1.password or a2.password or a3.password) is
initialized again at line 13.
How could we create 3 Long objects for one Account object???
OCPJP 6.
In Your Pursuit Towards Certification, NEVER Give Up.
OCA Java 6, OCP Java 6, OCP Java 8
Weeds: because mother nature refuses to be your personal bitch. But this tiny ad is willing:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
|