/** * Example Derived class * @author Brad Rippe */ public class DerivedClass extends BaseClass { public int derivedInt = 0; /** * Indicates whether some other object is "equal to" this one. * @param obj the object to check for equality * @return true if the the obj is equal to this DerivedClass, otherwise false */ public boolean equals(Object obj) { System.out.println("DerivedClass Equals"); if(obj == null) return false; if(obj == this) return true; // instance of this type? if(!(obj instanceof BaseClass)) return false; if(!(obj instanceof DerivedClass)) return false; // compare primitive types DerivedClass dc = (DerivedClass) obj; if(this.derivedInt != dc.derivedInt) return false; // if DerivedClass composition // compare their objects with the // .equals() return true; } }