posted 7 years ago
Hello, everyone. I am new in coderanch. Sorry me if this question has already been posted, I couldn't find the answer. I am preparing for OCA exam and in chapter 1 there is a question about garbage collector:
Suppose we have a class named Rabbit. Which of the following statements are true?
(Choose all that apply)
A. The Rabbit object from line 3 is first eligible for garbage collection immediately
following line 6.
B. The Rabbit object from line 3 is first eligible for garbage collection immediately
following line 8.
C. The Rabbit object from line 3 is first eligible for garbage collection immediately
following line 12.
D. The Rabbit object from line 4 is first eligible for garbage collection immediately
following line 9.
E. The Rabbit object from line 4 is first eligible for garbage collection immediately
following line 11.
F. The Rabbit object from line 4 is first eligible for garbage collection immediately
following line 12.
The answer is B,D. The Rabbit object from line 3 has two references to it: one and three. The references
are nulled out on lines 6 and 8, respectively. Option B is correct because this
makes the object eligible for garbage collection after line 8
-----------------------------------------------------------------------------------------------------------
My question is, doesn't object from line 3 have 3 references to it: one, three and four?
Shouldn't object four be nulled in order for object one to be eligible for garbage collection?
-----------------------------------------------------------------------------------------------------------