I got this from K&B certification exam book but my question is not about garbage collection. I don't really understand the reference a1.b1 = b1. What does this mean? I understand that a1 is an instance of Alpha and that b1 is a Beta object in the Alpha class. Does it mean that the Beta in the Alpha class has a reference to itself??? And if so why does it need a reference to itself?
Vonique Leary wrote:I don't really understand the reference a1.b1 = b1. What does this mean?
It's true that the Alpha class contains a couple of Beta references--one static and one instance member. However, in the main method of the class Tester, a couple of local Beta instances are created (using the same variable names). So in the code snippet:
a1.b1 (the static Beta variable in the a1 Alpha instance) has assigned to it the value of the local Beta variable b1, and similarly for the other two assignments. So nothing is being assigned to itself in this case. The reason for using the same variable names b1 and b2 is presumably just to make the question a little trickier and to make sure that you're thinking clearly about what's going on.
So after a1, b1, and b2 are set to null, which (if any) of the Beta instances are eligible for garbage collection?
Yes, that has refreshed my memory. I get the garbage collection part. It's the simple things that seem to escape me (the assignment of references to objects still confuses me). I don't get to study very often but when I do I lose track of what I have already learned. But your answer brought it back!
Thanks so much,
WHAT is your favorite color? Blue, no yellow, ahhhhhhh! Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop