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 different states of a thread in java?
Are arrays classes in java?
These static constructors are correct ? class A { statc intA() { } static A(int x,int y) { } static A(int x) { } }
Is 0 a prime number?
What is a function easy definition?
What do you mean by buffering?
How do you add an element to an arraylist in java?
What is the difference between throw and throws keywords?
What is the platform?
Is linkedlist thread safe in java?
when a request is generated from apache tomcat 5.5 and goes to oracle 10g or mysql,,, how the oracle or mysql reads the request as apache is a web server and oracle 10g is application server? when the oracle 10g provides response, how the apche tomcat reads it???
What is the difference between I ++ and ++ I in java?
Which sorting algorithm is in place?
what is the final keyword denotes in java?
How does java pattern compile work?