I don't understand why in Point class where I call the method on an object , it returns false. So, in method, in third/fourth/fifth case it returns false even if values of x and y of every objects are zero.
class Point{
private int x;
private int y;
public Point(int x, int y) {
this.x = x;
this.y = y;
}
public boolean method(Point p) {
if (p!=null)
return x==p.x && y==p.y;
else return false;
}
}
public class AppPoint{
public static void main(String[] args) {
Point p = new Point (0, 0);
Point q = new Point (0, 0);
Object r = new Point (0, 0);
Object s = new Point (0, 0);
System.out.println(p.method(p));
System.out.println(p.method(q));
System.out.println(p.method(r));
System.out.println(r.method(q));
System.out.println(r.method(s));
}
}
// method return: true true false false false