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

How do you classify Dialog Box?

857


Can we create a class inside a class in java?

760


What are advantages and disadvantages of OOPs?

882


Tell me about different OOPS concepts.

805


If I don't provide any arguments on the command line, then what will the value stored in the string array passed into the main() method, empty or null?

1021


Which package is imported by default?

847


What is stringreader?

722


What is the difference between size and length in java?

750


What are the limitations of procedural programming approach?

776


what is thread? : Java thread

771


What is visibility mode?

743


What is pre increment and post increment in java?

723


Is void a data type in java?

747


What does @override mean?

796


What do bitwise operators do?

757