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
How to sort an array from smallest to largest java?
How do you do exponents in java?
What is the difference between stringbuffer and stringbuilder class?
What are the procedures?
Explain about public and private access specifiers?
How will you load a specific locale?
What is contract between hashcode and equal method?
What is externalizable?
When do you get classcastexception?
What is boolean used for?
Enlist diffrent types of inheritance supported by java?
Which class is the superclass for every class in java programming?
what is encapsulation in java? Explain
What are runtime exceptions?
Differece between class and generic class?