This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Java in General and the fly likes How the protected finalize method is called by garbage collector Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "How the protected finalize method is called by garbage collector " Watch "How the protected finalize method is called by garbage collector " New topic
Author

How the protected finalize method is called by garbage collector

Gourab Guha
Greenhorn

Joined: Nov 06, 2006
Posts: 13
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
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Why do you say that the garbage collection code must not be in the java.lang package?
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

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 .


[Jess in Action][AskingGoodQuestions]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How the protected finalize method is called by garbage collector
 
Similar Threads
finalize() method - protected
finalize method
doubt in the signature of finalize() (SCJP)
Garbage Collector
Garbage Collector magic