Jesper de Jong wrote:You don't always want your objects to be cloneable. Sometimes you have classes that represent something that should not be cloneable.
Unfortunately, the designers of the Java language used an odd design when they added this feature to class Object. There's a protected clone() method which throws a CloneNotSupportedException, unless the class implements interface Cloneable. Interface Cloneable is a marker interface (an interface without any methods - its only purpose is to indicate that the class that implements it is allowed to be cloned). If you want, you can override the clone() method in your class and make it coderanch.
Hi Jesper, Thanks for the reply.
actually i doubt on the thing that, why this clone() method is not accessible directly from any user defined class's object. As we know, the protected methods can be accessed by classes which inherit the superclass (In our case class Nil inherit class Object).
So , with this rule in mind, if i do this :
Nil n=new Nil();
n.clone(); <----- here's the compiler error that the clone() is not found for n.
I agree that it throws cloneNotSupportedException if i won't implement cloneable. but my point is why this method is not visible for any user defined class ?
Hope you got this now .....