/** * Overloaded methods * @author gtowell * Created: Feb 2021 * Modified: Jul 2021 */ public class Inherit3 extends Object { private int value; //just hold a value from the constructor. /** * No arg constructor. Calls the int constructor with 0. */ public Inherit3() { this(0); } /** * Constructor. Just sets the internal value. * @param vvv */ public Inherit3(int vvv) { this.value = vvv; } /** * Applies only top equals when the object is of type Inherit3 * @param o3 the object to be compared * @return true!!! */ public boolean equals(Inherit3 o3) { System.out.print("I am here "); return o3.value == this.value; } public static void main(String[] args) { Inherit inhA = new Inherit(); Inherit3 inhB = new Inherit3(6); Inherit3 inhC = new Inherit3(6); // use the overridden equals System.out.println("Equals " + inhB.equals(inhA)); // uses the overloaded equals System.out.println("Equals " + inhB.equals(inhC)); // uses the overridden equals System.out.println("Equals " + inhB.equals((Object) inhC)); } }