With the help of runtime
polymorphism, the Object o which is an argument to the equals method, can be ANY object - for example, one can call
etc. This would result in the condition o instanceof Moof = false and thus the method equals() would return false. This is the prefered implementation, used in the
Java API - when calling equals to compare two objects of different class hierarchies, the equals method returns false.
So the method equals() can possibly return true only if the passed object o is instanceof Moof.
The instanceof
test is important, because in the "if" clause, you make a down-cast and you want to avoid RuntimeException (in this case, ClassCastException).
Hope this helps.
(It may be helpful for you to review runtime polymorphism and down-casting in the K&B book.)