对象深复制抛出异常
import java.util.Scanner; interface Cloneable{
Object clone();
}
public class Circle implements Cloneable{
public double R;//半径
Circle(){}
Circle(double a)
{
R=a;
}
public Circle clone(){
Circle obj=null;
try{
obj=(Circle)super.clone();
}
catch(CloneNotSupportedException e)
{
System.out.println("异常");
}
return obj;
}
public static void main(String [] args)
{
while(true)
{
System.out.println("请输入数!");
double j;
Scanner sc=new Scanner(System.in);
j=sc.nextDouble();
Circle c=new Circle(j);
Circle c1=(Circle)c.clone();
System.out.println(" "+c1.equals(c));
System.out.println(" "+c1.R);
}
}
}