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
What are extraneous variables examples?
Difference between linkedlist and arraylist.
Is arraylist a class in java?
What are annotations in java?
What are memory tables?
What is the use of jtable?
How to perform binary search in java?
How infinite loop is declared?
What is primitive array?
What does arrays sort do in java?
Is java a utf 8 string?
How can we make sure main() is the last thread to finish in java program?
Can you call a method on a null object?
What is the advantage of functional interface in java 8?
What is numel matlab?