• Post Reply Bookmark Topic Watch Topic
  • New Topic

What does this assignment mean?  RSS feed

 
Vonique Leary
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator






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?

Walk me through this, someone..........please???

Thanks,
Vonique
 
Kurt Van Etten
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vonique Leary wrote:I don't really understand the reference a1.b1 = b1. What does this mean?


Hi Vonique,

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?
 
Wouter Oet
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are still confused then try the search. This question has come up lots of times.
 
Vonique Leary
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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,
Von
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!