Win a copy of Murach's Java Programming this week in the Beginning Java forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

garbage collector Java SE 8 chapter 1 question 19  RSS feed

 
Mahammad Khalilov
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?


-----------------------------------------------------------------------------------------------------------
 
Norm Radder
Rancher
Posts: 2041
26
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Shouldn't object four be nulled

It is null because one was set to null on line 6 before four got the value from one.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!