• Post Reply Bookmark Topic Watch Topic
  • New Topic

why finalize() method is protected?  RSS feed

 
T sandya
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why finalize() method is declared as protected? instead of declaring as private?

Regards,
sandya.
 
Leandro Melo
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If it was private you wouldn't be able to override it.
 
zainu Mehmood
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i think the Question should be like why it is not public???
 
T sandya
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's protected because that's how you say in Java "you may override this, but you generally shouldn't be calling it." That fits here -- finalize() isn't meant to be called by user code.
 
T sandya
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Even if we declate that as public and still we can override and even we are not calling. am i right?

Regards,
Sandya.
 
Juggy Obhi
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To prevent it's access by code outside the class.(It's not Public)
To let it open for overriding.(It's not Private)
[ July 08, 2007: Message edited by: Juggy obhi ]
 
Raghavan Muthu
Ranch Hand
Posts: 3389
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, that sounds valid. Just to hide it from outside world (not public) and to be available for overriding (protected).
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!