}
public class CloneTest
{
public static void main(String[] args)
{
A a= new A();
try
{
a.doKooll();
A b=(A)a.clone(); // ** compile time error here stating clone has protected access in Object.
}
catch(CloneNotSupportedException e)
{
System.out.println("err");
}
// A b=(A)a.clone();
}
}
would anyone please tell that if clone is protected in object then it must be accessible from the same package but here it is not allowing to do so ..... why? btw output of program is "err"
yeah i have read in order to an object to be cloneable it must implement marker interface Cloneable but my question is if the method in object class is protected then it should be accessible from the same package containing the class code.....
ankur trapasiya wrote:yeah i have read in order to an object to be cloneable it must implement marker interface Cloneable but my question is if the method in object class is protected then it should be accessible from the same package containing the class code.....
clone() is part of Object and which is in java.lang package. You cannot access the method via the instance from a different package. Either you can access it via inheritance(The first type of use in your code) or access it in the same package.