Equals () of the three methods to be reloaded in Java data abstraction ()
Boolean equals (Object x );
This method is very different from the operator "=". equals checks whether the value of an object is logically equal. That is, "=" simply determines whether the object reference is the same.
The equivalence of equals requires the following relationships: Self-inverse, symmetry, transmission, non-null, and consistency.
package equalsTesting;public class Person {private String name;private int age;public Person(String name,int age){this.name = name;this.age = age;}public boolean equals(Object x){if(this == x) return true;if(x == null) return false;if(this.getClass()!= x.getClass()) return false;Person that = (Person)x;if(this.name != that.name) return false;if(this.age != that.age) return false;return true;}public static void main(String[] args) {// TODO Auto-generated method stubPerson p1 = new Person(jay,30);Person p2 = new Person(kim,29); Person p3 = new Person(jay,30);System.out.println(p1.equals(p2));System.out.println(p2.equals(p1));System.out.println(p1.equals(p3));System.out.println(p3.equals(p1));System.out.println(p1.equals(null));}}