This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Java in General and the fly likes finalize method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "finalize method" Watch "finalize method" New topic
Author

finalize method

kamal vashist
Greenhorn

Joined: Sep 13, 2006
Posts: 2
Why there is protected keyword before finalize() method.
Waiting for prompt reply.
Thank you
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4968
    
    1

protected is a valid access modifier, regardless of how a method is decorated.

Is there a particular method you're concerned about?

-Cameron
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

Hi,

Welcome to JavaRanch!

A "protected" method can only be called by subclasses of the defining class, or other methods in the same package. It's not perfect, but here it's being used to suggest that it's OK (actually encouraged) for you to call super.finalize() when you're overriding finalize(), but you shouldn't ever need to call finalize() on some other object. Only the garbage collector is supposed to call it. The "protected" therefore prevents you from making calls you shouldn't make.


[Jess in Action][AskingGoodQuestions]
Srinivas Kalvala
Ranch Hand

Joined: Oct 20, 2005
Posts: 257

Hello,

The protected method makes only the same and sub type object can call the finalize, and all other can't call those and as Ernest told only GC is supposed to call it.
 
 
subject: finalize method
 
Similar Threads
difference between finally and finalize()
finalize
Gc question
why finalize() can't be defined as private?
Finalization Method