Page 919 - AP Computer Science A, 7th edition
P. 919

18.
(C ) Ex pres s ion III is t rue: T he compareTo m et hod is implemented to return 0 if two Position objects have the same row and column. Expression I is false because object1 == object2 returns true only if object1 and object2 are the same reference. Expression II is tricky. One would like p1 and p3 to be equal since they have the same row and column values. This is not going to happen automatically, however. The equals method must explicitly be overridden for the Position class. If this hasn’t been done, the default equals method, which is inherited from class Object, will return true only if p1 and p3 are the same reference, which is not true.

































































































   917   918   919   920   921