Here is the "Inheritance and finalize( )" example of ch7 in the book "thinking in java--2e":
Output by typing "java Frog":
Not finalizing bases
Creating Characteristic is alive
LivingCreature()
Creating Characteristic has heart
Animal()
Creating Characteristic can live in
water Amphibian()
Frog()
Bye!
Frog finalize
finalizing Characteristic is alive
finalizing Characteristic has heart
finalizing Characteristic can live in water
Output by typing "java Frog finalize":
Creating Characteristic is alive
LivingCreature()
Creating Characteristic has heart
Animal()
Creating Characteristic can live in water
Amphibian()
Frog()
bye!
Frog finalize
Amphibian finalize
Animal finalize
LivingCreature finalize
finalizing Characteristic is alive
finalizing Characteristic has heart
finalizing Characteristic can live in water
The book explains that--
"When you use composition to create a new class, you never worry about finalizing the member objects of that class. Each member is an independent object, and thus is garbage collected and finalized regardless of whether it happens to be a member of your class. With inheritance, however, you must override finalize( ) in the derived class if you have any special cleanup that must happen as part of garbage collection. When you override finalize( ) in an inherited class, it�s important to remember to call the base-class version of finalize( ), since otherwise the base-class finalization will not happen."
Why "the base-class finalization will not happen" since
Java API says "finalize()is called by the garbage collector on an object when garbage collection determines that there are no more references to the object"?
(Sorry for the long post!)