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
explain autoboxing in java?
What is definition and declaration?
What is time complexity java?
What is operator overloading. Is it is supported in java?
Where we write javascript code in html page?
What do you understand by casting in java language?
Does sprintf add a null terminator?
Can you instantiate the math class in Java?
What is e in java?
How many types of methods are there in java?
What design pattern you have used in your project? I answered Factory pattern, how it is implemented? What are its advantage? Do know about Abstract Factory?
Why call by value prevents parameter value change?
Explain spliterator in java8?
What is the abstraction?
Explain what access modifiers can be used for variables?