d1.name ="clover" System.out.println(new Dog("clover");// prints Dog Key as output
d1.name ="arthur" System.out.println(new Dog(clover"));// prints nulll
OUTPUT given is
null Dog Key null
My doubt is why is first one printing null? when we changed the key object d1's name to magnolia, it should get reflected in the Map too right?, As I understand it is the reference address of the object that gets stored in the collection(not the object itself). So when hashcode of magnolia is checked it should give 8. and the key object has name as magnolia and its hashcode should match. ??? Am I missing something???
Or, is it that the bucket number where the Object is stored does not change, based on any changes in the key object, once it is stored???
Why does the first println display Dog Key. We are actually displaying a new object of Dog class with name "Clover". Same case with the second println statement. Just in case we have overriden toString() method, displaying the name, we would get "Clover" and "Clover" as the output. How did you get the output as Dog Key and null. Can you cross check that again?