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 |
Difference between a Scrollbar and a ScrollPane?
class A { public void disp(int a,int b) { System.out.println("hai"); } } class B { public void disp(int a,int b,int c) { System.out.println("hai"); } } above program is overloading or overriding?
How do you compare values in java?
heavy components means what?
What is a function easy definition?
waht happens when a return type ,even void is specified for a constructor?
How do I write a self declaration?
I have 2 objects inside one object(vector). how can i serialize one of them. I dont want to serialize the second one
Hi, This is ravi i have a question like this i have string "UNDERSTAND" now i want to count the letters how many times it occures.i.e from the above string the out put should be like this U-1,N-2,D-2,E-1,R-1,S-1,T-1,A-1. how can i achieve this Thnaks in advance for your response ..
What is inheritance?
5 Answers Accenture, Hexaware, Syntel,
What are the types of methodology?
Difference between stack and queue?