0

Referring to objects using equals?

I'm having a rough time explaining my questing so I'm trying to make a simplified example to get my point across without having to post my entire 300+ lines of code. SO when you're modifying an object's methods (i.e. : "object.methodName(parameter);"), this sets the values of the method that its calling based on "parameter" how can I refer to those specific objects in the subclass itself, outside of the main class. say, object1.setTotal(50) object2.setTotal(40) is in my main class then, in the subclass I'd like to do this essentially: comparte total of object 1 to total of object 2, return higher of the two totals. this would essentially be the method in the subclass, based off the UML that I was given public object compareTo(object other){ ?? } bare with me, I'm a noob still :[

22nd Mar 2017, 5:55 AM
Zeffeler
Zeffeler - avatar
1 Answer
+ 10
If you want to compare all properties of the object, overwrite equals and hashCode. If you want to compare one property, declare a get method in the super class and override it in the subclasses. Then call both gets in the calling class and compare the values.
23rd Mar 2017, 5:40 AM
Tashi N
Tashi N - avatar