Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

Why do we need to override equals() and hascode() method of object class?

Answer Posted / javamasque

As per equality contract of Java if two objects are equal then they should return equal integer, means if obj1.equals(obj2) then obj1.hashCode() == obj2.hashCode();

As we override equals method we compares equality on value of each property inside 1st object with 2nd object, as it finds all properties are equal then returns true else false.

As we override hascode method we generate a unique integer by multiplying with prime number. If we multiply with prime number then there is most possibility to get unique integer. The prime number 31 is mostly used as the hascode method is override.

Is This Answer Correct ?    2 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

If A Class Is Declared Without Any Access Modifiers, Where May The Class Be Accessed?

1121


Define how does a try statement determine which catch clause should be used to handle an exception?

1065


What is the main difference between java platform and other platforms?

996


How many java versions are there?

997


What is string in java? String is a data type?

956


What do you mean by local class?

952


Can we have two main methods in a java class?

989


Can we call the run() method instead of start()?

983


What does percent mean in java?

966


What is a return in java?

976


What does i ++ mean in Java?

888


Is java a compiler?

919


What is mysql driver class name?

1076


What is java oops?

995


what is meant by abstract class?

1060