aspose file tools*
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 Java 8 in Action this week in the Java 8 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: 24168
    
  30

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: finalize method
 
Similar Threads
finalize
Finalization Method
Gc question
difference between finally and finalize()
why finalize() can't be defined as private?