nerdexam
Oracle

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.

Java Basics

Question

Given the code fragment:

Which statement is true?

Exhibit

1Z0-803 question #110 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)
  • A
    17% (5)
  • B
    3% (1)
  • C
    69% (20)
  • D
    10% (3)

Why each option

This question assesses understanding of Java's garbage collection mechanism and when objects become eligible for collection.

AAfter line 8, three objects are eligible for garbage collection.

Without the specific code fragment, claiming three objects are eligible is incorrect based on the provided answer.

BAfter line 8, two objects are eligible for garbage collection.

Without the specific code fragment, claiming two objects are eligible is incorrect based on the provided answer.

CAfter line 8, one object is eligible for garbage collection.Correct

(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.

DAfter line 8, none of the objects are 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

#garbage collection#object lifecycle#references

Community Discussion

No community discussion yet for this question.

Full 1Z0-803 Practice