diff --git a/Program b/Program index d3670de..69c9b9b 100644 --- a/Program +++ b/Program @@ -1,31 +1,32 @@ class Parent { - void show() { System.out.println("Parent's show()) + void show() { + System.out.println("Parent's show()"); + } } // Inherited class -class Child extends { +class Child extends Parent { // This method overrides show() of Parent - @Override void sho() - { - System.out.println( Child's show()); + @Override + void show() { + System.out.println("Child's show()"); } } // Driver class class Main { - public static void main(String[] args) - { + public static void main(String[] args) { // If a Parent type reference refers // to a Parent object, then Parent's // show is called - Parent obj1 = new Parent() + Parent obj1 = new Parent(); obj1.show(); // If a Parent type reference refers - // to a Child object Child's show() + // to a Child object, Child's show() // is called. This is called RUN TIME // POLYMORPHISM. - Parent obj2 = new Child() - obj.show(); + Parent obj2 = new Child(); + obj2.show(); } }