This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Java in General and the fly likes finallizer() & clone method are protected Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "finallizer() & clone method are protected" Watch "finallizer() & clone method are protected" New topic

finallizer() & clone method are protected

Manish Thapliyal

Joined: Aug 07, 2007
Posts: 17
why the finallizer() & clone method are protected . why not public or private
Please explain.

amitabh mehra
Ranch Hand

Joined: Dec 05, 2006
Posts: 98
Manish, you can check this thread for the same:why is finalize() protected
Bill Shirley
Ranch Hand

Joined: Nov 08, 2007
Posts: 457
Some people would suggest avoiding clone() altogether.

An old thread will give some more detail on clone().

The default implementation will throw an exception - no need for anyone to call it. If you override it, you can make it public.

Bill Shirley - bshirley -
if (Posts < 30) JavaRanchFAQ);
Peter Chase
Ranch Hand

Joined: Oct 30, 2001
Posts: 1970
Originally posted by Bill Shirley:
Some people would suggest avoiding clone() altogether

... and others would suggest avoiding finalize() altogether, too.

Both finalize() and clone() are relics from the very earliest days of Java. They aren't as well thought-out as later features. Luckily, extremely few programs really need finalize() [use weak or phantom references instead], and few need clone().

I consider cloning of arrays to be a special case. It's the most efficient way to copy a whole array, and there are no confusions with how to override the array-cloning method, because you can't.

Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
I agree. Here's the link:
subject: finallizer() & clone method are protected
It's not a secret anymore!