// Base Class class Shape { void draw() { System.out.println("Shape's draw()"); } } // Inherited class class Rectangle extends Shape { // This method overrides draw() of Shape @Override void draw() { System.out.println("Rectangle's draw()"); } } public class MethodOverriding { public static void main(String[] args) { // If a Parent type reference refers // to a Parent object, then Parent's // show is called Shape shape = new Shape(); shape.draw(); Rectangle rectangle = new Rectangle(); rectangle.draw(); } }