posted 17 years ago
Hello Friends,
I have doubt in the following code:
The output comes as:
null
Dog key
null
I am not able to understand why the line 6 is giving o/p as null.
My understanding for above code is:
This thing I understood that when d1.name is set to "magnolia"in line 1, then line 2 prints null beacuse the d1 object saved earlier in the map has name as "clover" . So the hashcode will be 8 but earlier it was 6.
But when line 5 changes d1.name as "arthur", but line 6 is printing the
dog object whose name is "clover" which was saved into the map, so the hashcode() will be 6 and equals should also satisfy, then why it is not returning "Dog key" instead of null.
I think I am not getting the logic of line 1 - line 6. Can anyone clarify my doubt?
Regards,
Lata