1

What I understood from Why is the clone() method protected in java.lang.Object? that since we are not cloning the object itself and to make use of cloning in any sub class we need to override it but what if the Object's contains public clone method? we still need to override it in sub class to make use of it.

Editing: In question Why is the clone() method protected in java.lang.Object? people are explaining why we have protected clone method in Object class, but my question is if the method in the class is public clone instead of protected clone we still need to implements Clonable interface in subclass to make use of cloning. So why we have not public method instead we have protected.

Community
  • 1
  • 1
Ankush soni
  • 1,439
  • 1
  • 15
  • 30
  • Yes, in that case you're required to declare any override public as well. Is that a problem for you? – Sneftel Jul 09 '15 at 10:15
  • No, I am in confusion why we have signature in Object class i.e. **protected native Object clone() throws CloneNotSupportedException** and why not **public native Object clone() throws CloneNotSupportedException** – Ankush soni Jul 09 '15 at 10:29
  • Are you confused about the question you linked? Or what you would have to do if you wanted a public clone method? – Evan Knowles Jul 09 '15 at 10:39

0 Answers0