有疑问请澄清我让我解释一下A班和B班2班
public class A implements Cloneable{
public static void main(String[] args) {
A a1 = new A();
try {
A a2 = (A) a1.clone();//works fine
} catch (CloneNotSupportedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
B b1 = new B();
B b2 = (B) b1.clone();//cannot get this method
}
}
class B implements Cloneable {
}
Run Code Online (Sandbox Code Playgroud)
当我编译此代码得到以下错误
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
The method clone() from the type Object is not visible
Run Code Online (Sandbox Code Playgroud)
我知道这两个类扩展了Java.lang.Object类请解释为什么class B不能得到clone()方法