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...

7) Suppose there is Student class like

class student {
int age;
string name;
}

We want to store these objects in a HashMap. Do we need to
override any methods in Student class? If any which ones
and why? what if i just override equals or just hashcode?
what will be the results in both the cases?

Answer Posted / manoranjan

Logically no need to override any method but problem with
this design will be that we can not find the objects stored
in the hashmap. So to overcome this problem we need to
override equlas() and hashcode() mathod of Object
class.According to Sun java guide line if equals() method is
teeling that two objects are equal then their hashcode must
be same.But reverse is not true.

Is This Answer Correct ?    10 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Can a final variable be initialized in constructor?

927


What is finally in Java?

1022


What is a null check?

941


Can we declare the static variables and methods in an abstract class?

949


What is the Concept of Encapsulation in OOPS

945


What does @override mean?

1119


what is meant by Byte code concept in Java?

1013


How do you implement tree mirroring in java?

1023


How do I print a “?

953


Are the imports checked for validity at compile time? Will the code containing an import such as java.lang.abcd compile?

1046


How do you remove all elements from an arraylist in java?

956


What are parsers? Dom vs sax parser.

991


What are format specifiers in java?

1003


Tell us something about an iterator.

902


What is the range of a character variable?

945