equals method in the object class: Regardless of the new number of objects, when using the"= ="to judge the memory address. If you need to make judgments between objects, you need to override the Equals method: Public BooleanEquals (Object obj)//obj is an incoming formal parameter (object) { if(obj = =NULL)//determines whether an object is empty { return false;//NULL returns False } Else { if(objinstanceofCat//determines whether this incoming parameter (object) is created by a cluster of cat{Cat C= (cat) obj;//cast this Obj object to cat type if(C.A = = This. A && C.B = = This. B//determine if the member variable in the C object is the same as the member variable in the Cat class { return true;//Yes True } Else { return false;//otherwise flase } } Else { return false;//not created from Cat returns Flase } } }
The Equals method in the object class in Java complements