Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
    Bookmark Topic Watch Topic
  • New Topic

Questions on GC from Khalid A.Mughal, Chap 9

 
Anuradha Prasanna
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
  • Report post to moderator
On page 402 & 403 of this book, there are no answers for four GC questions.

1)How many objects are eligible for GC when control reaches (1)?


I think, 9 objects are eligible for GC. is that right?
but the answers are,
(A)0
(B)5
(c)10

can anyone tell the right answer with explanation?
--------------------------------------------------------------------------------------------------------------------------------------
2)How many objects are eligible for GC when control reaches (1)?

I think, 0 objects are eligible for GC. is that correct?

--------------------------------------------------------------------------------------------------------------------------------------

3)How many objects are eligible for GC when control reaches (1)?


I think, 0 objects are eligible for GC here. Is that right?
--------------------------------------------------------------------------------------------------------------------------------------

4) How many objects are reachable when control reaches (1)?


I think 5 objects are reachable.(Integer[] obj with reference array & 4 objects pointed to by the references array[0], array[1], array[2], array[3])
is it correct?
 
Burk Hufnagel
Ranch Hand
Posts: 814
3
  • Mark post as helpful
  • send pies
  • Report post to moderator
Anuradha,

You're posting in the wrong forum. This looks like a question for the SCJP forum.

BTW, I didn't look at the rest but your answer for #1 is wrong. Take a look at the code, a new instance of Eligible gets created each time through the loop but no reference is kept. So the correct answer is the number of times the loop executes - which isn't nine.

Good luck with your studies. I recommend Kathy Sierra and Bert Bate's SCJP Study Guide - but I'm partial as I was one of the technical reviewers. Still I've used it as the textbook for an SCJP study group and everybody seemed to like the book and the folks who took the exam passed so I guess there's objective proof that it's a good book. Of course it doesn't hurt that KAthy and Bert helped write the exam...

Burk
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65115
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Report post to moderator
Please do not cross-post the same question in multiple forums. It wastes people's time when multiple redundant conversations take place. Please read this for more information.
 
    Bookmark Topic Watch Topic
  • New Topic