【发布时间】:2012-07-05 21:15:59
【问题描述】:
当我尝试克隆通用 Object 时,我得到编译时错误。为什么?
Object obj=new Object();
obj.clone(); // Here compile time error "The method clone() from the type Object is not visible"
每个类都扩展Object 类,并且克隆方法在Object 类中受到保护。
protected 方法可以在同一个包中访问,也可以通过subclasses 访问,所有类都是java.lang.Object 的子类。
【问题讨论】: