There is a bug in the implementation of equals method in class Point below. Identify the bug and answer the question.
class Point {
Point(int x, int y) {
x_ = x;
y_ = y;
}
public boolean equals(Point p) {
if( p == null )
return false;
return ( this == p ) ||
( p.x_ == x_ && p.y_ == y_ );
}
// .. hashCode is implemented too
private int x_;
private int y_;
}
Create 2 instances of Point and call equals as follows:
Point p1 = new Point(10, 20);
Point p2 = new Point(10, 20);
Object p3 = p2;
// call equals
String result = p1.equals(p2)
+ " "
+ p1.equals(p3);
What will be the value of result above?