I am re-reading the creation of Java Stuart Reges programs and notice that I do not quite understand. This applies to method overloading equals()in any new class. Suppose we define a class as such:
public Point{
private int x;
private int y;
public Point(int x, int y){
this.x = x;
this.y = y;
}
public getX(){
return this.x;
}
public getY(){
return this.y;
}
}
The book shows that at any time when we define a new class, the equals () method that we define for the new class should be written as such:
public boolean equals(Object o) {
if (o instanceof Point) {
Point other = (Point) o;
return x == other.x && y == other.y;
} else {
return false;
}
}
equals "Object", "Point"? , equals equals Object, ( , , ). , , , ...
String equals(), Point, String, false. equals() ( ) , ?