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 is listnode in java?
What is integers and example?
How to reverse string in java?
What is treeset and treemap in java?
How are the elements of a gridbaglayout organized?
Are floats faster than doubles?
Can finally block be used without a catch?
What is thread pool in java with example?
Which is a valid identifier?
What state is a thread in when it is executing?
Can we have any code between try and catch blocks?
Explain Basics of OOP Language in java
What is final keyword in java? Give an example.
What are the different types of multitasking?
Explain spliterator in java8?