• Post Reply Bookmark Topic Watch Topic
  • New Topic

about core java  RSS feed

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why clone method is declared as protected in object class




bye
kalyan
 
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

Post your Java related queries in Java in General(Advanced) forum.
 
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to Java In General (Intermediate)...
[ August 17, 2004: Message edited by: Gregg Bolinger ]
 
ranger
Sheriff
Posts: 17309
11
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Kalyan"-
Welcome to the JavaRanch! Please adjust your displayed name to meet the

JavaRanch Naming Policy.

You can change it

here.

Thanks! and welcome to the JavaRanch!

Mark
 
Ranch Hand
Posts: 823
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Kalyan,

Welcome to JavaRanch!

You seem to be getting a bit of a hard time from the various bartenders and sheriffs round here so, assuming that you're now fully conversant with the rules for naming, which forum is appropriate for your query and not to post multiply, I'm going to throw you a bone.

We're really a friendly bunch here at JavaRanch. Take a look at this Being a Descendant of Object page of Sun's Java Language Tutorial. Hopefully that should improve your understanding.

The simple answer to your question is that classes that can be cloned (i.e. have a functional clone() method) must implement the Cloneable interface. Object does not but its descendants can, if they choose, as they inherit the protected clone() method. Not a great explanation, but it might help.

Jules
 
Ranch Hand
Posts: 1211
IntelliJ IDE Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kalyan,

I think the idea with having clone as protected is that, some classes may not want cloning to be part of their public interface, that is for some objects you do not want to allow cloning, or it does not make sense.

If clone was declared public, every class will have to make sure that it implements 'cloning' properly, but with it being protected, you have the choice of implementing that bit of functionality, and making it public if you so wish.

HTH
Sonny
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!