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?
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 .