有关clone接口的问题
设计一个点Point类,圆类Circle继承点类,分别实现clone方法,实现一个测试类来实现Circle的自我复制。(提示:实现clone接口)public class Point implements Cloneable
{
private int x;
private int y;
public Point()
{
}
public Point(int X, int Y)
{
x=X;
y=Y;
}
public void setX(int X)
{
x=X;
}
public void setY(int Y)
{
y=Y;
}
public int getX()
{
return x;
}
public int getY()
{
return y;
}
public Object clone()
{
Point obj=null;
try
{
obj =(Point)super.clone();
}
catch (CloneNotSupportedException e)
{
e.printStackTrace();
}
return obj;
}
}
public class Circle extends Point implements Cloneable
{
private int r;
public Circle()
{
}
public void setR(int R)
{
r=R;
}
public int getR()
{
return r;
}
public Object clone()
{
Circle o=null;
try
{
o =(Circle)super.clone();
}
catch (CloneNotSupportedException e)
{
e.printStackTrace();
}
return o;
}
}
Point类编译成功,但Circle类失败了,显示:
在相应的try语句主体中不能抛出异常 java.lang.CloneNotSuppotedException