Object的clone()方法

作者: ldsea 分类: 程序生活 发布时间: 2008-09-09 20:58

[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]

一条评论
  • wave

    2009年6月25日 17:36

    [emot]shock[/emot]<>

发表回复

您的电子邮箱地址不会被公开。