This is code from Head First Java 3rd edition. It wants me to figure out something about eligibility for the Garbage Collector. I'm having trouble with some basic concepts that I didn't see the book discussing. I have some questions about the code before looking into Garbage Collection. I copied and pasted two parts of the code at the top to ask things about it. I
A lot of examples in HFJ are aimed at people who are hoping to sit a certification exam; in this case the reader is expected to work out how many objects are “unreachable”. Such questions can come up in the exam.
The correct way to answer it is to get pencil and paper, and write down which vaiable points to which object. Try it with the two methods first. Work out which of the methods do and don't make any changes that actually last after the method completes. When the main() method completes, you should work out how many objects have been created and are no longer reachable.
I suggest you go back and revise what it says about methods and what their modifiers and return types are.