package hash;

public class HashCodes {
    public static void main(String[] args) {
        
        /*The <tt>equals</tt> method for class <code>Object</code> implements 
        the most discriminating possible equivalence relation on objects; 
        that is, for any non-null reference values <code>x</code> and
        <code>y</code>, this method returns <code>true</code> if and only
        if <code>x</code> and <code>y</code> refer to the same object
        (<code>x == y</code> has the value <code>true</code>).*/
        
        System.out.println("Object - hashCode() and equals()");
        System.out.println("------------------------------------");
        Object o1 = new Object();
        Object o2 = new Object();
        System.out.println("o1: "+o1.hashCode());
        System.out.println("o2: "+o2.hashCode());
        System.out.println(o1.equals(o2)); 
        
        //Hash Codes
        
        // For the String class, the equals method is overridden
        System.out.println("\nString Objects - hashCode() and equals() overridden");
        System.out.println("------------------------------------");
        String s1 = new String("a");
        String s2 = new String("a");
        System.out.println("s1: "+s1.hashCode());
        System.out.println("s2: "+s2.hashCode());
        System.out.println(s1.equals(s2)); 
        
        System.out.println("\nVehicle Objects - hashCode() and equals() overridden");
        System.out.println("------------------------------------");                 
        Vehicle v1 = new Vehicle('1',"ABC123","Honda","Accord",1988);
        Vehicle v2 = new Vehicle('1',"ABC123","Hond.","Acc.",1988);
        System.out.println("v1: "+v1.hashCode());
        System.out.println("v2: "+v2.hashCode());
        System.out.println(v1.equals(v2));
        
//        System.out.println(v1);
//        System.out.println(System.identityHashCode(v1));
    }
}


