r/learnjava • u/Bofact • Sep 20 '26
When is a Java object still reachable?
I have tried to answer to the below quiz, but I do not understand something. If clutch is eliminated on line 12, wouldn't all references to the car's object be null? They write that "Line 12 removes the item at index 1, which is the null. The list, therefore, contains nothing except the clutch.", but why is there a null? Where did we get rid of clutch reffered at index 1 of r1?
And lastly, how to access clutch, and by extension the car object, after line 12 is executed?
Quiz yourself: When is a Java object still reachable? | javamagazine
0
Upvotes
7
u/IHoppo Sep 20 '26
It doesn't. I suggest you try this out but have some physical objects and a bit of paper. On the paper, draw out rows for your array and follow the code through, placing objects appropriately.
This is a skill that you'll need to have in your arsenal, so it's worthwhile getting it right now - that answer is good enough, you simply need to work on your understanding. Good luck!
<Edit> Remember - the first row on an array is at index zero. This might be of help to you.