I have been going through the Java tutorials on the Java website and have been left confused with an answer they gave to a question.
The question is as follows: "The following code creates one array and one string object. How many references to those objects exist after the code executes? Is either object eligible for garbage collection?"
String[] students = new String[10];
String studentName = "Peter Smith";
students[0] = studentName;
studentName = null;
Answer: "There is one reference to the students array and that array has one reference to the string Peter Smith. Neither object is eligible for garbage collection."
Why is studentName not eligible for garbage collection? Nothing is pointing to studentName, and it's value is null.