Follow Our FB Page << CircleMedia.in >> for Daily Laughter. We Post Funny, Viral, Comedy Videos, Memes, Vines...


Hi, well i am unable to understand that why it is mandatory
to have same hashcode, if two objects are same?

Thanks in advance.

Answers were Sorted based on User's Feedback



Hi, well i am unable to understand that why it is mandatory to have same hashcode, if two objects a..

Answer / nalluri

Hi,

No. Never same hash code to 2 same objects. every object is
having it's own hash code.

Is This Answer Correct ?    2 Yes 0 No

Hi, well i am unable to understand that why it is mandatory to have same hashcode, if two objects a..

Answer / venkateswara reddy

NO No NO....
Check it once..
If there r two same objects, there must be a diffent
hashcode to them....
U never find same hashcode to any two objects

Is This Answer Correct ?    1 Yes 0 No

Hi, well i am unable to understand that why it is mandatory to have same hashcode, if two objects a..

Answer / rajshekaran pillai

As the JVM assigns the hashcode to an object value and not
the reference the hashcode for the same object will be same.
the equals() method of the object class uses this hashcode
to evaluate if the objects have same value. therefore

Object o1 = new String("ABC");
Object o2 = "ABC";

/**
* will have the same hashcode
* therefore when we do..
*/
if(o1 == o2){
System.out.println("The object reference is same");
}else if(o1.equals(o2)){
System.out.println("The object has same value");
}

/**
* The output is
* The object has same value
*/

Is This Answer Correct ?    1 Yes 0 No

Hi, well i am unable to understand that why it is mandatory to have same hashcode, if two objects a..

Answer / prasanna

If two objects are equal then there hashcode must same.

Is This Answer Correct ?    1 Yes 1 No

Hi, well i am unable to understand that why it is mandatory to have same hashcode, if two objects a..

Answer / nalluri

Hi,

No. Never same hash code to 2 same objects. every object is
having it's own hash code.

Is This Answer Correct ?    0 Yes 0 No

Post New Answer



More Core Java Interview Questions

Which is better 64 bit or 32 bit?

0 Answers  


What is difference between array and arraylist in java?

0 Answers  


How to sort a vector elements that contains the user define class object? (Note: If Suppose consider, A Student class contain two data members. They are String studentName and int rollNo. I am creating Four objects for this class, each object contains students details like name and roll no. Now i am storing that objects in vector and if i retiving the elements from the vector means then it should be display in sorting order)

3 Answers   ProdEx Technologies,


What is multiple inheritance? Is it supported by java?

0 Answers  


When should we create our own custom exception classes?

0 Answers  






Different types of modifiers?

8 Answers   RoboCom,


What is treeset in java?

0 Answers  


java is fullu object oriented or pure? why?

8 Answers  


class a extends b { } class b extends a { } why java doesn't support cyclic pls explain me with example

3 Answers   Wipro,


How do you compare two strings lexicographically?

0 Answers  


What is diffrance between FINALIZE() & FINALLY ?

2 Answers   Infosys,


What is meant by vector class, dictionary class, hash table class, and property class?

0 Answers  






Categories