🎴 Flashcard Mode
Java Programming Fundamentals
Card1 / 16
Mastered0
Review0
QuestionClick to flip
The following code creates one array and one string object. which object is eligible for garbage collection after the code executes? ... String[] students = new String[10]; String studentName = "Peter Parker"; students[0] = studentName; studentName = null; ...
AnswerClick to flip back
A
Neither Object
💡 Explanation:
Tracing the code: after creating the array and String, assigning 'students[0] = studentName' creates a second reference to 'Peter Parker'. Setting 'studentName = null' only removes one reference. The array object is still referenced by 'students' variable, and the String object is still referenced by 'students[0]'. Neither object loses all references, so neither is eligible for garbage collection.