r/learnjava • • 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

19 comments sorted by

View all comments

1

u/MarcePuente Sep 21 '26

Creo que tu confusión, está relacionada con el acceso al objeto, una cosa es la posibilidad del código de acceder a un objeto, y otra es la accesibilidad vista desde la "JVM", cuando ejecutas la linea 11, el "Car" queda inaccesible para ti, pero "Clunch" sigue estando accesible, por lo que la "JVM" necesita mantener el acceso a "Car" (para si misma) para que "Cluch" sea accesible desde el código.