This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Mock Exam Errata and the fly likes mindQ no.37 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Mock Exam Errata
Bookmark "mindQ no.37" Watch "mindQ no.37" New topic

mindQ no.37

Haining Mu
Ranch Hand

Joined: Jun 01, 2001
Posts: 51
37. 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.
answer a,b,c
Why c is correct? it is legal NOT invoke super's finalize, right?
Manfred Leonhardt
Ranch Hand

Joined: Jan 09, 2001
Posts: 1492
Hi Haining,
Yes it is legal to do it either way. However, using common sense we can realize that we will be overriding the superclass method (which means it doesn't get called). Any special handling that the Superclass implemented will be lost. Therefore, good programming practice is to call the Superclass finalize method from within our finalize method to keep the memory clean.
NOTE: The choice C is not explaining what is legal and what is not legal. The key word in the sentence is should.
Jane Griscti
Ranch Hand

Joined: Aug 30, 2000
Posts: 3141
This is a nit but, the finalize() method is not always called; it is only called if the gc has not invoked it before. Question should say 'the finalize() method is guaranteed to be called at least once before an object is garbage collected'
Jane Griscti
Sun Certified Programmer for the Java� 2 Platform

Jane Griscti
SCJP, Co-author Mike Meyers' Java 2 Certification Passport
Cathy Song
Ranch Hand

Joined: Aug 24, 2003
Posts: 270
I think the right answers are a,c. Am I correct?
I agree. Here's the link:
subject: mindQ no.37
It's not a secret anymore!