Somewhere deep in an explanation of a different question in a different test,
it was explained, please correct me if i am wrong, that the first thing that the equals() method does is to check if both objects
belong to the same class...(or extending each other. Probably using the instaceof operator....)
In question 2.1125, the explanation says, "The equals methods of all wrapper classes first check if the two object are of same class or not. If not, they immediately return false", which is correct.
So, it is possible that an equals method may return true even if the class of the passed object has no relation to this object.
But, in that case, its a violation of contract of the equals method overriding, on such questions cant we assume that, programmer wont violate the contract?
No, it wouldn't necessarily be a violation of the equals contract. The contract says that it needs to be reflexive, symmetric, transient, and consistent. You can satisfy these even with two different classes.
From the statement, the first part tells you that a.equals(b) returns true. While the code that you've given will not even compile. So I am not sure how are you interpreting.
a and b should be variables of some class (not of type int!) such that a.equals(b) return true. You can now think of cases where this holds true and then determine whether b instanceof ClassOfA will also return true or not. ClassOfA is whatever class you choose.