File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Mock Exam Errata
Bookmark "mindQ no.37" Watch "mindQ no.37" New topic
Author

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.
Regards,
Manfred.
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: http://aspose.com/file-tools
 
subject: mindQ no.37
 
Similar Threads
MindQ's 37 mock
MindQ (Q.37) GC
GC doubt!
Garbage Collection
garbage collection question.