object클래스의 clone() 메서드 부분에서의 질문입니다.
package a;
class multi {
public static void main(String args[]) {
Point obj1 = new Point(10,10);
Point obj2 = (Point)obj1.clone();
obj2.setX(50);
obj2.setY(100);
System.out.println("obj1 = " + obj1);
System.out.println("obj2 = " + obj2);
}
}
class Point implements Cloneable {
int x,y;
Point(int x, int y) {
this.x = x;
this.y = y;
}
void setX(int x) {
this.x = x;
}
void setY(int y) {
this.y = y;
}
public Object clone() {
try {
return super.clone(); <- 왜 super클래스의 clone메서드를
호출해야 하는지 의미를 잘 모르겠
습니다.
}
catch(CloneNotSupportedException e) {
return null;
}
}
public String toString() {
return "(" + x + "," + y + ")";
}
}