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

Why is string class considered immutable?

0 Answers  


Explain features of interfaces in java?

0 Answers  


The class "Class" is belongs to which package?? a) java.lang b)java.lang.reflect c)java.util d)None

4 Answers  


How a string is stored in memory?

0 Answers  


Can a abstract class be declared final?

0 Answers  






What is final?

0 Answers  


What are access specifiers in java ?

0 Answers   Akamai Technologies,


When do we use synchronized blocks and advantages of using synchronized blocks?

0 Answers  


what is the difference between sleep() and Wait()?

10 Answers   Accenture, Amdocs,


Are constructors methods?

0 Answers  


What are the six ways to use this keyword?

0 Answers  


What do you understand by casting in java language?

0 Answers  


Categories