为什么Object类的clone方法不能从任何类直接访问?

时间:2018-06-19 11:48:32

标签: clone icloneable

/ ** B类可以访问其父类的受保护的方法。那么为什么A类不能访问其父类(对象)的受保护的克隆方法呢?*** /

class A{

    protected void m1() {
        System.out.println("Inside A:m1()");
    }
}

/*Class B may be in same or in different Package but still it can access the m1()*/

class B extends A{

}

public class Test {

    public static void main(String[] args)

        B ob1=new B();
        ob1.m1();//Works perfectly fine 

        A ob2=new A();
        ob2.clone();//The method clone() from the type Object is not visible


    }

}

0 个答案:

没有答案