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


Please Help Members By Posting Answers For Below Questions

What is classpath?

552


What are the types of relation?

577


Which programming language is best in future?

527


Explain the difference between call by refrence and call by value?

567


how do I create a runnable with inheritance? : Java thread

509






What is the function of compareto in java?

595


What is the difference between equals() and == in java?

531


Why do I need to declare the type of a variable in java?

568


Is empty set an element of empty set?

608


What does @param args mean in java?

556


Explain static nested classes ?

599


Can we declare array without size in java?

555


What does three dots mean in java?

656


what is recursion in java

602


What is comparable and comparator interface? List their differences

583