There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
SCJP 5.0 OCBCD 5.0(Formerly SCBCD)
Vijay Vishwa wrote:Object.clone() method is protected. Since all the class are indirectly subclass of Object, It is possible to call the clone method. But the call will fail by throwing CloneNotSupportedException unless the clone method is overridden. The cloning is not supported by default.
This is wrong.
CloneNotSupportedException is only thrown if the class does not implement Cloneable.
SCJP 5.0 OCBCD 5.0(Formerly SCBCD)
Vijay Vishwa wrote:
This is wrong.
CloneNotSupportedException is only thrown if the class does not implement Cloneable.
Yes, thats right, that's what i mentioned at the end to implement Cloneable interface.
Vijay Vishwa wrote:But the call will fail by throwing CloneNotSupportedException unless the clone method is overridden.
simon fletcher wrote:I get the "clone() has protected access in Object" message when compiling. If anyone could pass me a hint as to where I have gone wrong, it would be appreciated.
Does protected mean that the class calling the clone method also HAS to be a subclass of the class the clone method is being called on?