The whole example is like below. Now can you explain?
If they're added to the end of MapTest.main():
d1.name = "magnolia";
System.out.println(m.get(d1)); // #1
d1.name = "clover";
System.out.println(m.get(new Dog("clover"))); // #2
d1.name = "arthur";
System.out.println(m.get(new Dog("clover"))); // #3
Remember that the hashcode is equal to the length of the name variable. When
you study a problem like this, it can be useful to think of the two stages of retrieval:
1. Use the hashcode() method to find the correct bucket
2. Use the equals() method to find the object in the bucket
In the first call to get(), the hashcode is 8 (magnolia) and it should be 6
(clover), so the retrieval fails at step 1 and we get null. In the second call to get(), the hashcodes are both 6, so step 1 succeeds. Once in the correct bucket (the "length of name = 6" bucket), the equals() method is invoked, and since Dog's equals() method compares names, equals() succeeds, and the output is Dog key. In the third invocation of get(), the hashcode
test succeeds, but the equals() test fails because arthur is NOT equal to clover.
(What happen in third case, they have not written the answer?)