• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

mindQ no.37

 
Haining Mu
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1492
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3141
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Cathy Song
Ranch Hand
Posts: 270
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think the right answers are a,c. Am I correct?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic