Why I can not use protected method from a sub class?

49 views Asked by At

clone() method in the Object class is protected, so why I have an error?

public class Test
{
    public static void main(String[] args)
    {
        Test2 c1 = new Test2();
        Test2 c2 = (Test2) c1.clone(); // error: clone() has protected access in java.lang.Object
    }
}

class Test2 implements Cloneable
{

}
0

There are 0 answers