This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
welcome to Javaranch!
When it comes to Garbage collection, an image is worth a thousand words, if you REALLY want to solve garbage collection problems ONCE-AND-FOR-ALL practice diagram drawing, it is NOT difficult, it took me ONLY 90seconds to solve this problem.
The answer is ONE object is 'eligible' for garbage collection. Which is the object referenced by 'a2.a'
I guess you REMEMBER that objects are 'eligible' for garbage collection when they have NO 'live reference' variables connecting them.
The ONLY way I can effectively explain this to you is via diagram drawing. (I promise to do that later today).
In Your Pursuit Towards Certification, NEVER Give Up.
One more thing, while you await my diagram explanation click on this LINK, when you are there scroll down to the bottom of the page, its an example of how I used diagram to resolve a garbage collection puzzle in this forum. Check it out, it might even give you a 'clue' on how I got the answer to your question.
The numbers placed in the reference variables fletchers correspond to each line of execution in the program I wrote... study it CAREFULLY. If you have doubts, I will be pleased to clarify them.
The diagram clearly demonstrates the answer.
REMEMBER that every instance of this class has its own 'COPY' of the rereference variable 'A a' declared in line 2 of the program.
During instantiation whatever argument you pass to the constructor is assinged to the reference variable
I hope this helps.
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com