This is taken from a Mock exam; (originally posted by Rita Kapoor.)
Which of the following statements about Java's garbage collection are true?
a) The garbage collector can be invoked explicitly using a Runtime object. b) The finalize method is always called before an object is garbage collected. c) Any class that includes a finalize method should invoke its superclass' finalize method. d) Garbage collection behavior is very predictable.
The given answer is a, b, c.
I agree with a. But b & c are not correct; see K&B pg 253.
Bert we need your help.
Joined: Jan 10, 2007
The question is taken from MindQ's Sun Certified Java Programmer Practice Test Updated 4/7/99.
b) The finalize method is always called before an object is garbage collected.
Isn't there some ambiguity in that statement?.
Finalize occurs 1 time before and object is garbage collected (when called by the jvm), but it does not happen just the moment before. The object can be resurrected or saved and then Garbage Collected.
SCJP 5.0 95%<br /> <br />The greatest enemy of knowledge is not ignorance, it is the illusion of knowledge.
IMHO perhaps the hardest SCJP topic to write mock questions for is GC. If the language is even just slightly vague, the whole question can be ruined. I have to say that the authors did a pretty good job with this question, but not quite good enough - I think that the way B, C and D were all worded leaves a little room for misinterpretation. I do agree with the discussion concerning resurrection however, and you might encounter a question on the real exam that uses this concept.
Given the difficulty of getting good quality GC questions, i think this is an excellent place to post them and discuss them. I will offer up an idea:
Why don't you guys take a stab at improving the language of the answers for this question? It would be a great exercise for everyone involved!
Spot false dilemmas now, ask me how!
(If you're not on the edge, you're taking up too much room.)