1

I have override the finalize() method to do some work while re-claiming the memory space of the objects.But somebody says that i have to call the parent's finalize() in the overriding the finalize() method.But constructor automatically calls it super class constructor unlike finalize() method.

Can you enlighten me something on this...?

Pratik
  • 30,639
  • 18
  • 84
  • 159
Saravanan
  • 11,372
  • 43
  • 143
  • 213
  • 1
    Also worth reading: http://stackoverflow.com/questions/158174/why-would-you-ever-implement-finalize – assylias Jan 23 '13 at 07:18

1 Answers1

8

It is defined that way in the Java Language Specification #12.6 (emphasis mine):

The finalize method declared in class Object takes no action. The fact that class Object declares a finalize method means that the finalize method for any class can always invoke the finalize method for its superclass. This should always be done, unless it is the programmer's intent to nullify the actions of the finalizer in the superclass. (Unlike constructors, finalizers do not automatically invoke the finalizer for the superclass; such an invocation must be coded explicitly.)

assylias
  • 321,522
  • 82
  • 660
  • 783
  • +1 because finalize() is a method, and methods don't call their super class's implementations by default. Given finalize should be avoided where possible adding special behaviour for it isn't likely to be a good idea either. – Peter Lawrey Jan 23 '13 at 08:35