/** * Overriding in Inheritance */ public class Inherit2 { /** * Override the toString method * "@Overide" tells computer that you believe you are overiding and inherited * method. If Computer disagrees, then an error. Not required, but it can detect errors * * No comments are needed on overrides that do not change functionality (list this). * @return a string representation of the object */ @Override public String toString() { // super.toString() calls the overridden toString method return "Inherit2 toString " + super.toString(); } /** * Override the default equals to do an equals comparison * using the hashcode method * @return true if the objects are the same */ @Override public boolean equals(Object o) { return true; } public static void main(String[] args) { Inherit inh1 = new Inherit(); Inherit2 inh2 = new Inherit2(); System.out.println(inh1); System.out.println(inh2); System.out.println("Equals " + inh1.equals(inh1)); System.out.println("Equals " + inh1.equals(inh2)); } }