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

explain autoboxing in java?

588


What is definition and declaration?

513


What is time complexity java?

526


What is operator overloading. Is it is supported in java?

512


Where we write javascript code in html page?

553






What do you understand by casting in java language?

566


Does sprintf add a null terminator?

549


Can you instantiate the math class in Java?

599


What is e in java?

535


How many types of methods are there in java?

517


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?

1928


Why call by value prevents parameter value change?

575


Explain spliterator in java8?

593


What is the abstraction?

577


Explain what access modifiers can be used for variables?

583