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 |
Inorder to specify a container?s layout, which method is used?
Why multiple inheritance is not supported by java?
Why is multiple inheritance not supported in java?
Brief the life cycle of an applet.
How do you compare two strings? any predefined method for this?
what happens when a thread cannot acquire a lock on an object? : Java thread
Can we override constructor in java?
what release of java technology are currently available what do they contain?
What is the difference between instanceof and isinstance?
What is the full meaning of java?
How many types of voids are there?
How to store image in arraylist in java?