Class Finalizers

   

Java™ 2 Primer Plus
By Steven Haines, Steve Potts

Table of Contents
Chapter 7.  Inheritance


Inherited constructors were already discussed: A super class's constructor is always called before a subclass's constructor, but the same is not true of finalizers. A super class's finalizer is not executed unless the subclass's finalizer explicitly calls it. Furthermore, it must be the last method called by subclass's finalizer. To invoke the super class's constructor you access it through the super variable, for example:

 public class MyClass extends MySuperClass {     protected void finalize() {        // Clean up this class        super.finalize();     }  } 

Thus, if MyClass's finalizer is invoked, the last thing it does is call MySuperClass's finalize method.


       
    Top
     



    Java 2 Primer Plus
    Java 2 Primer Plus
    ISBN: 0672324156
    EAN: 2147483647
    Year: 2001
    Pages: 332

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net