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

In case of inheritance what is the execution order of constructor and destructor?

1055


Can we override the static method?

962


Can private class be extended java?

963


Can we create a class inside a class in java?

991


Can you extend main method in java?

1093


Which of the following is not an isolation level in the JDBC

2073


What is the protected method modifier?

988


Break statement can be used as labels in java?

943


For class CFoo { }; what default methods will the compiler generate for you>?

1022


How many techniques can be employed to create a string object?

1028


Why we cannot override static method?

988


Do we need to manually write Copy Constructor?

975


What are the 6 boolean operators?

1019


Explain about abstract classes in java?

983


What is garbage collection? What is the process that is responsible for doing that in java?

1055