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?



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

Answer / 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

More Core Java Interview Questions

why string is not taking as primitive datatypes but we r taking it as a class? why explain it?

2 Answers   HP, SparkTG,


How do I start learning java?

0 Answers  


How do you ensure that n threads can access n resources without deadlock?

0 Answers  


What is the r character?

0 Answers  


What is difference between synchronize and concurrent collection in java?

0 Answers  


what is diffrence between .NET and java?

2 Answers  


What is the use of object and class classes?

0 Answers  


What are init(), start() methods and whey they are called?

2 Answers  


What is classname class in java?

0 Answers  


Write a program to find the greatest of three numbers in java?

0 Answers  


Can an interface be final?

0 Answers  


What is a java lambda expression?

0 Answers  


Categories