Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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

Thanks in advance.

Answer Posted / 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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are multiple inheritances? Is it supported by java?

895


Why java is made?

924


Define interface in java?

1034


What are constants and how to create constants in java?

946


What is mvc in java?

969


What is a java developer salary?

924


What are the various access specifiers in java?

960


How many tetrahedral voids are there in bcc?

1021


Explain when noclassdeffounderror will be raised ?

999


What is string data type?

919


Why pointers are not used in java?

1062


Which container method is used to cause a container to be laid out and redisplayed in java programming?

1061


Which is better singleton or static class?

934


What are the changes in java.io in java 8 ?

976


Name few java.lang classes introduced with java 8 ?

943