Why java.lang.Object can not be cloned?

clone, java

Solution

Because `clone` is protected in the `Object` class. It's not `public`.

The only way to get access to an object's `clone()` method is to know it has a compile-time type that has a public `clone()` method.

Problem

When i try to clone a generic Object i get compile time error . why? ``` Object obj=new Object(); obj.clone(); // Here compile time error "The method clone() from the type Object is not visible" ``` Every class extends Object class and clone method is protected in Object class. `protected` methods can be accessed in same package as well as by `subclasses` and all classes are child of `java.lang.Object`.

Original source

Related problems