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.
Because
cloneis protected in theObjectclass. It’s notpublic.The only way to get access to an object’s
clone()method is to know it has a compile-time type that has a publicclone()method.