Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Possible error OCJP Practice Exams, exam 3 question 28

 
John Wintermute
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
 
Thomas Kennedy
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
 
Jagat Sastry
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?
 
An Tran
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