Object的clone()方法

[code]class A implements Cloneable {
  // 重写Object的clone
  public Object clone() throws CloneNotSupportedException {
    return (A) super.clone();
  }

  public String toString() {
    return "Hello,World!";
  }
}

class B {
  public static void main(String[] args) throws CloneNotSupportedException {
    A x = new A();
    Object y = (A)x.clone();
    System.out.println(y.toString());
  }

}[/code]

Object的clone()方法》有一个想法

回复 wave 取消回复

您的邮箱地址不会被公开。 必填项已用 * 标注