• Post Reply 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

Possible error OCJP Practice Exams, exam 3 question 28

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

When I worked through this question, I ended up with five objects, but the answer says it's only four. It seems to me that one Banker, one Account and three Longs are created



I ran the code through the debugger in Eclipse and, indeed, Long instances are created with different IDs at lines 1,2 and 3.

Would anyone care to comment on that?

Many thanks!
-john
 
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You didn't post the exact question. If it asked you how many objects are created by the whole program that's one thing, but if it asked how many are created between certain lines that's another.

I'm going to examine how many are created just within the go() method.


I think the supplied answer, four objects, is correct if they meant just the doings within the go() method.
 
John Wintermute
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Thomas,

Yes, you are indeed correct - it's how many are eligible when the method ends. Another case of "read the question properly"

thanks!

john
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
John, I think you're right. The question asks "When line 8 is reached, which are true?"

When line 8 is reached, you have those 4 objects mentioned by Thomas, plus the Banker object created in line 7 that would be eligible for GC.
That makes it five objects eligible for GC, right?
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, it's 5 and was confirmed by the author here http://www.coderanch.com/t/531928/java-programmer-SCJP/certification/Garbage-Collection-found-OCP-Java
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!