1
class Base {

    public static void display() {
        System.out.println("Static or class method from Base");
    }

    public void print() {
        System.out.println("Non-static or Instance method from Base");
    }
}

class Derived extends Base {

    public static void display() {
        System.out.println("Static or class method from Derived");
    }

    public void print() {
        System.out.println("Non-static or Instance method from Derived");
    }
}

// Driver class   
public class Test {
    public static void main(String args[]) {
        Base obj1 = new Derived();
        obj1.display();
        obj1.print();
    }
}

The output of this code is showing -

Static or class method from Base
Non-static or Instance method from Derived

Can anyone explain me why is it so ??

Yassin Hajaj
  • 21,337
  • 9
  • 51
  • 89
  • See below post: [Why doesn't Java allow overriding of static methods?](https://stackoverflow.com/questions/2223386/why-doesnt-java-allow-overriding-of-static-methods) – Hamed Jun 13 '18 at 06:38

0 Answers0