Object.class 에 들어가보면
public boolean equals(Object obj) {
return (this==obj);
}
으로 비교 결과값을 true, false로 반환해주는 boolean으로 알려준다.
class Circle {
int radius;
public Circle(int radius) {
this.radius = radius;
}
public class Test {
public static void main(String[] args) {
Circle obj1 = new Circle(10);
Circle obj2 = new Circle(10);
if (obj1 == obj2) System.out.println("2개의 원은 같습니다.");
else System.out.println("2개의 원은 같지 않습니다.");
}
}
}
2개의 원은 같습니다.
Object.class 에 들어가보면
public String toString() {
return getClass().getName() + "@" + Integer.toHexString(hashCode());
}
으로 되어있는것을 볼 수 있다.
Car car01 = new Car();
Car car02 = new Car();
System.out.println(car01.toString());
System.out.println(car02.toString());
Car@15db9742
Car@6d06d69c
public Circle shallowCopy() {
Object obj = null;
try {
obj = super.clone();
}
catch (CloneNotSupportedException e) {}
return (Circle)obj;
}
public Circle deepCopy() {
Object obj = null;
try {
obj = super.clone();
}
catch (CloneNotSupportedException e) {}
Circle c = (Circle)obj;
c.p = new Point(this.p.x, this.p.y);
return c;
}