The instanceof test is required for equals method to know that you are comparing the objects which are comparable.
This statement might be vague, so I will give an example. For example If I have a code like this.
This returns Not Equal because the String and StringBuffer are not comparable. Both classes derived from Object but there is not relation between String class Objects and StringBuffer class Objects, so the instanceof test inside equals method in String class will fail and as a result it will return false.
I hope this is clear.
Joined: Jun 18, 2007
Fred I am talking about K & B book.
Padma I got your point. Thanks for that. But here in boolean equals() we have to do instanceof test for ToDos. So my question was that?