Пример с переопределением hashCode и equals

class Point
{
    private int x;
    private int y;
    public Point(int x,int y)
    {
        this.x=x;
        this.y=y;
    }
    public int getX() {
        return x;
    }
    public int getY() {
        return y;
    }
    @Override
    public int hashCode() {
        int result=17;
        result=result*37+x;
        result=result*37+y;
        return result;
    }
    @Override
    public boolean equals(Object obj){
        if (!(obj instanceof Point))
            return false;
        Point p = (Point)obj;
        return x==p.x && y==p.y;
    }

}

public class Main {

    public static void main(String[] args) {
       Point p1=new Point(1,2);
       Point p2=new Point(1,1);
       Point p3=p1;

       System.out.println(p1);
       System.out.println(p1.hashCode());
       System.out.println(p2);
       System.out.println(p2.hashCode());
       System.out.println(p3);

       System.out.println(p1.equals(p3));
       System.out.println(p1.equals(p2));

       String s1=new String("HEllo");
       String s2=new String("Hello");
       System.out.println(s1.equals(s2));
        System.out.println(s1.hashCode());
        System.out.println(s2.hashCode());

    }
}