Win a copy of Rust Web Development this week in the Other Languages forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

What does this assignment mean?

 
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
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
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic