Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How the protected finalize method is called by garbage collector

 
Gourab Guha
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear All,

I have a double regarding the calling mechanism of finalize method. The access specifier of finalize method is protected, not only that if a class overrides this method then also the finalize method can be protected in the subclass of Object. But the concept of protected access specifier is, from outside of the package it can be accessed only from subclass.
The program (may be part of Garbage collector), which calls this (finalize) method mast not be in the same package (that is java.jang) nor it is a subclass of the class (whose finalize method it calls).
Then how the finalize method is getting called by the garbage collector when it is protected?

Regards,
Gourab
 
Paul Clapham
Sheriff
Pie
Posts: 20719
30
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why do you say that the garbage collection code must not be in the java.lang package?
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The garbage collector is not written in Java, in any event. The virtual machine itself can do all sorts of things that you can't do from Java code. Other examples include constructing but not initializing objects, as is done by Object.clone() and by ObjectInputStream .
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic