Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Tim Cooke
  • Bear Bibeault
  • paul wheaton
Saloon Keepers:
  • Carey Brown
  • Stephan van Hulst
  • Tim Holloway
  • Mikalai Zaikin
  • Piet Souris
Bartenders:

Questions on GC from Khalid A.Mughal, Chap 9

 
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 883
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 67732
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Don't touch me. And dont' touch this tiny ad:
Low Tech Laboratory
https://www.kickstarter.com/projects/paulwheaton/low-tech-0
    Bookmark Topic Watch Topic
  • New Topic