Why do we need to override equals() and hascode() method of object class?
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 |
Explain about main thread in java?
How is treeset implemented in java?
Define a java class.
What does the “static” keyword mean? Can you override private or static method in java?
What is bitwise complement?
How do you create a reference in java?
What is serialVersionUID and what is its need?
Which class should you use to obtain design information about an object
What is object-oriented paradigm?
How to check if linked list contains loop in java?
What does \ mean in regex?
What is singleton math?