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 meta-annotations?
How to store image in arraylist in java?
Why is singleton class used?
Explain super keyword in java.
How many types of gc are there in java?
What is the difference between double and float variables in java?
Define an abstract class with reference to java.
Why is multithreading important?
Is there any way to skip finally block of exception even if some exception occurs in the exception block?
What is the purpose of the enableevents() method?
Can you make a constructor final?
How can you write a loop indefinitely in java programming?
What do you mean by static variable?
Can a final variable be initialized in constructor?
What is logical variable?