This week's book giveaway is in the HTML Pages with CSS and JavaScript forum.
We're giving away four copies of Testing JavaScript Applications and have Lucas da Costa on-line!
See this thread for details.
Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

finalize method

 
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is the below given statement true or false. please give the reason also.
Thanks
Any class that includes a finalize method should invoke its superclass' finalize method.
 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Any class that includes a finalize method should invoke its superclass' finalize method.


Correct me if Im wrong, but I think the answer is true. In contrast to constructors, finalize methods do not implicitly call their superclass' finalizers.
Example: If the superclass uses the finalize method to close a database connection and the subclass doesnt do that in its own finalize, then the databse connection is never closed when using an object of the subclass. Hence, you should call the super finalize() inside finalize() of subclass.
 
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're not wrong. From the Java Language Spec:

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, which is usually good practice. (Unlike constructors, finalizers do not
automatically invoke the finalizer for the superclass; such an invocation must be
coded explicitly.)

 
Sanyev Babu
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Richard and Karel

Sanyev
 
You don't like waffles? Well, do you like this tiny ad?
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic