The following code creates one array and one string object. How many references to these objects exist after code execution? Is it the right to collect garbage?
... String[] students = new String[10]; String studentName = "Peter Parker"; students[0] = studentName; studentName = null; ...
My answer was studentName has the right to garbage collection. But the answer that was indicated does not meet the requirements. What I thought students [0] refer to String "Peter Parker", and studentName also does the same. Now this is studentName to null, students [0] still refer to "Peter Parker" (I checked this by printing it). The explanation given to students [0] still refers to studentName, so studentName is also not allowed to collect garbage. m not understanding this, since studentName now refers to null, and students [0] refer to "Peter Parker". I understand what is wrong?
java string
getsuga
source share