Hallo....ich frage mich warum mir Java bei dieser Shallow Copy eine CloneNotSupportedException Rauswirft....aber seht selbst:
mfg,
Han
Code:
public class Figure implements Cloneable{
int x,y;
String name;
public Figure(int x, int y, String name){
this.x = x;
this.y = y;
this.name = name;
}
public Object clone() throws CloneNotSupportedException{
return super.clone();
}
}
public class Circle extends Figure{
Color color;
public Circle(int x, int y, String name, Color color){
super(x,y,name);
this.color = color;
}
}
public class Test {
/**
* @param args
*/
public static void main(String[] args) {
Figure a = new Circle(10,20,"Hannes",Color.red);
Figure b = (Circle)a.clone(); //CloneNotSupported Exception
}
}
mfg,
Han