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 a final variable be initialized in constructor?
What is finally in Java?
What is a null check?
Can we declare the static variables and methods in an abstract class?
What is the Concept of Encapsulation in OOPS
What does @override mean?
what is meant by Byte code concept in Java?
How do you implement tree mirroring in java?
How do I print a “?
Are the imports checked for validity at compile time? Will the code containing an import such as java.lang.abcd compile?
How do you remove all elements from an arraylist in java?
What are parsers? Dom vs sax parser.
What are format specifiers in java?
Tell us something about an iterator.
What is the range of a character variable?