• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

finalize method

 
kamal vashist
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why there is protected keyword before finalize() method.
Waiting for prompt reply.
Thank you
 
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper
Posts: 4968
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Srinivas Kalvala
Ranch Hand
Posts: 257
Firefox Browser Hibernate Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic