• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Assessment Test, Question #10 (Java OCA 8 Programmer I Study Guide)

 
Saad Benbouzid
Greenhorn
Posts: 21
Chrome IntelliJ IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I found this question not only tricky but straight unfair.
I've become very good at solving garbage collection questions, with my pen and my piece of paper next to me, but this question really annoyed me by the way it is written.

Why is answer D correct ? I think it can't be known since the garbage collector is unpredictable.
What if GC was called by the JVM just between line 9 and 10 ? Then you would have "g1" gc-collected after line 10 and answer D would be wrong since there would be no more grasshopper eligible for garbage-collection.

Why don't you keep this question as clear as for the exams 1 to 3 ? That is to say stating something like "Grasshopper from line 7 is first eligible for garbage-collection immediately after line 9", why this kind of unfair grammar innovation ?
The keyword here is "first", it dispels all ambiguities that come with the asynchronous and unpredictable GC mechanism.

 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Saad Benbouzid wrote:I found this question not only tricky but straight unfair.

I don't agree with you! This question is not unfair, maybe a little bit tricky. But it just test your knowledge about when an object is eligible for GC and when it's not. Because two reference variables are referring to Grashopper "g2", assigning null to one of them will have no influence on the number of objects being eligible for GC. That's why answer option D is correct as well.

Saad Benbouzid wrote:Why is answer D correct ? I think it can't be known since the garbage collector is unpredictable.
What if GC was called by the JVM just between line 9 and 10 ? Then you would have "g1" gc-collected after line 10 and answer D would be wrong since there would be no more grasshopper eligible for garbage-collection.

That's why this advice is very important: NEVER assume something which is not mentioned in the question. If they want to test you about what happens when garbage collection had run, it would be clearly mentioned in the question and/or the answer option(s).

Hope it helps!
Kind regards,
Roel
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 35279
384
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agree with Roel. I think the question is fine.

For the real exam, you'd have two clues not to worry about the case of GC being called after line 9.
1) The real exam tells you how many answers are correct.
2) There is no answer about the answer being unknown.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic