@@ -0,0 +1,2002 @@
+package inheritance;%0A%0A/**%0A * Method overriding rule%0A * - Overriding method must have same signature as method in parent class%0A * - Overriding method must be same or more accessible than method in parent class%0A * - Overriding method must not throw new or broader checked exception than exceptions thrown in parent method%0A * - If method returns value, it must be same or subclass of that type returned in parent class%0A *%0A * For static method, it is called hiding method%0A *  - Static method must remain static when overridden, same for non-static methods%0A *%0A * Calling Overridden method follows what object is called on%0A * Calling Hidden method follows what reference is called on%0A *%0A * For class fields, it same as static method, they are hidden%0A *%0A */%0Aclass A %7B%0A    static void staticMethod() %7B%0A        System.out.println(%22Static method in A%22);%0A    %7D%0A    void instanceMethod()%7B%0A        System.out.println(%22Instance method in A%22);%0A    %7D%0A    private int getIntValue() %7B%0A        return 0;%0A    %7D%0A%7D%0A%0Aclass B extends A %7B%0A    // It is hiding parent method%0A    static void staticMethod()%7B%0A        System.out.println(%22Static method in B%22);%0A    %7D%0A%0A    // It is overriding%0A    void instanceMethod() %7B%0A        System.out.println(%22Instance method in B%22);%0A    %7D%0A%0A    // It is overriding%0A    int getIntValue()%7B%0A        return 1;%0A    %7D%0A%7D%0A%0Apublic class OverrideMethod %7B%0A    public static void main(String%5B%5D args) %7B%0A        A a = new B();%0A        a.instanceMethod();     // Instance method in B%0A        a.staticMethod();       // Static method in A%0A%0A        new B().instanceMethod();                   // Instance method in B%0A        new B().staticMethod();                     // Static method in B%0A        System.out.println(new B().getIntValue());  // 1%0A%0A        new A().instanceMethod();                   // Instance method in A%0A        new A().staticMethod();                     // Static method in A%0A        //System.out.println(new A().getIntValue());  // DOES NOT COMPILE, inaccessible as it is private%0A    %7D%0A%7D%0A

Call to Overriding method follows object while call to Hidden method follows reference