1Z0-803 · Question #110
Given the code fragment: Which statement is true?
The correct answer is C. After line 8, one object is eligible for garbage collection.. This question assesses understanding of Java's garbage collection mechanism and when objects become eligible for collection.
Question
Given the code fragment:
Which statement is true?
Exhibit
Options
- AAfter line 8, three objects are eligible for garbage collection.
- BAfter line 8, two objects are eligible for garbage collection.
- CAfter line 8, one object is eligible for garbage collection.
- DAfter line 8, none of the objects are eligible for garbage collection.
How the community answered
(29 responses)- A17% (5)
- B3% (1)
- C69% (20)
- D10% (3)
Why each option
This question assesses understanding of Java's garbage collection mechanism and when objects become eligible for collection.
Without the specific code fragment, claiming three objects are eligible is incorrect based on the provided answer.
Without the specific code fragment, claiming two objects are eligible is incorrect based on the provided answer.
(Assuming the missing code fragment creates at least two objects and then reassigns a reference variable, causing one of the initially created objects to lose its only active reference.) When an object is no longer referenced by any active variable, it becomes unreachable and thus eligible for garbage collection.
Without the specific code fragment, claiming no objects are eligible is incorrect based on the provided answer.
Concept tested: Java garbage collection eligibility
Source: https://docs.oracle.com/javase/tutorial/java/data/garbagecollection.html
Topics
Community Discussion
No community discussion yet for this question.
