//谁帮我看下我这错在哪里呢 怎么用Clone ?
public class Clone
{
public static void main(String[] agrs) throws CloneNotSupportedException
{
Table table = new Table();
table.setCenter(new Point(2, 3));Table clonedTable = (Table) table.clone();
System.out.printf("正版:(%d, %d)\n",
table.getCenter().getX(),table.getCenter().getY());System.out.printf("克隆版:(%d, %d)\n",
clonedTable.getCenter().getX(),clonedTable.getCenter().getY());
}
}class Point implements Cloneable
{
private int x;
private int y;public Point() {};
public Point(int x, int y)
{
this.x = x;
this.y = y;
}
public void setX(int x)
{
this.x = x;
}
public void setY(int y)
{
this.y = y;
}
public int getX()
{
return x;
}
public int getY()
{
return y;
}
public Object clone() throws CloneNotSupportedException
{
return super.clone();
}
}
class Table implements Cloneable
{
private Point center ;public void setCenter(Point center)
{
this.center = center;
}
public Point getCenter()
{
return center;
}
public Object clone() throws CloneNotSupportedException
{
Table table = (Table) super.clone();
if(this.center != null)
{
table.center = (Point) super.clone();
}
return table;
}
}就是想用下Clone方法复制个对象而已。