jQuery in Action, 2nd edition*
The moose likes Beginning Java and the fly likes finalize access specifiers protected/private/public Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "finalize access specifiers protected/private/public " Watch "finalize access specifiers protected/private/public " New topic

finalize access specifiers protected/private/public

Siva kandasamy
Ranch Hand

Joined: Dec 31, 2002
Posts: 139
Hi There,
Refer the example #1 "Finalize.java" below. Change the finalize method with following piece of code
void finalize(){
private void finalize(){

The question is, If we do that, we get compilation error. Please help me to understand, why do I get compilation error; if I use access specified other than public or protected.
Hope my question make sense.
Thanks in Advance

*********** Example #1 **************************
// Finalize.java

class TestA {
void Hello(){

protected void finalize(){
class Finalize {

public static void main(){
[ January 02, 2003: Message edited by: Sivanantham kandan ]
Cindy Glass
"The Hood"

Joined: Sep 29, 2000
Posts: 8521
If the method is private then only the class itself can call it. This is a reserved method that is ONLY to be called by the gc. For the gc to get AT it, it needs to have an appropriate accessibility.

"JavaRanch, where the deer and the Certified play" - David O'Meara
Ilja Preuss

Joined: Jul 11, 2001
Posts: 14112
Because finalize is declared protected in java.lang.Object and Java doesn't allow you to reduce visibility in subclasses.

The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Siva kandasamy
Ranch Hand

Joined: Dec 31, 2002
Posts: 139
Make sense. Thanks.
[ January 03, 2003: Message edited by: Sivanantham kandan ]
I agree. Here's the link: http://aspose.com/file-tools
subject: finalize access specifiers protected/private/public
Similar Threads
Protected Class--> Error
finalize access specifiers public/protected/private
Why Compiler error?.....