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
Can bool be null?
What is string args [] in java?
Can java list contain duplicates?
How to use Media tracker Class.
Which class cannot be a subclass in java?
Is there a jre for java 11?
Where is the find and replace?
What is string immutability?
What are the four versions of java?
What is square root in java?
What do you understand by java?
What is the difference between Java1.4 and Java1.5
What is the use of conditional statement?
What is an iterator java?
How do you delete a list in java?