SCJP 1.5
Spot false dilemmas now, ask me how!
(If you're not on the edge, you're taking up too much room.)
SCJP 1.5
I'm not seeing how 200 makes it any different. Is c3 referencing the same object that c1 was? Or is c3 referencing a new object that the go() method returned?
Sorry about that, but story s/b 200 not 5. it's in the errata posted at the top of the forum, and here:
https://coderanch.com/t/253802/java-programmer-SCJP/certification/Updated-Errata
So with the new value for variable story as per the errata above, total 4 objects becomes eligible for garbage collection....the option not mentioned in the question.
----------
Ravinder
Why c2:
Because a copy of the c2 object's address was passed as an argument to the go() method invoked on c1 object. Inside the method, reference variable cb which holds the address of c2 object was also assigned a null value, thereby making the object commonly referenced by c2 and cb eligible for garbage collection.
"Know where to find the solution and how to use it - that's the secret of success."
SCJP 5.0<br />-----------<br />"Help Ever && Hurt Never"
Amir, may be you are right but as far as I know any changes made to the object references passed as an argument reflects outside. So if we make cb=null then it will automatically make C2 to be null.
And also u are saying in your explaination itself that cb & C2 refers to the same object hence proved.
So if C1 is eligible for GC then why not C2???
Originally posted by Swapnil Trivedi:
Amir Explained: "When go() method is called, both c2 and cd refer to same object. So when we set cb to null it will not have any affect on c2 which still refer to same object. Thus this object will not be elligible for GC( as c2 refer it)"
Amir, may be you are right but as far as I know any changes made to the object references passed as an argument reflects outside. So if we make cb=null then it will automatically make C2 to be null.
And also u are saying in your explaination itself that cb & C2 refers to the same object hence proved.
SCBCD 1.3: 94%<br />SCWCD 1.4: 91%<br />SCJP 5: 95%
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime. |