super keyword can be used to invoke parent class method: Example: Animal class

Java Programming Language Class, Object and Methods in java (Article) Class, Object and Methods in java (Program)

3934

Program:

 class Animal {
   public void eat() {
      System.out.println("Animals eat..");
   }
}

class Dog extends Animal {
   public void eat() {
      super.eat();   // invokes the super class method
      System.out.println("Dogs eat meet");
   }
}

public class SuperKeyword {

   public static void main(String args[]) {
      Animal ob = new Dog();   // Animal reference but Dog object
      ob.eat();   // runs the method in Dog class
   }
}

Output:

Animals eat..
Dogs eat meet
Press any key to continue . . .

This Particular section is dedicated to Programs only. If you want learn more about Java Programming Language. Then you can visit below links to get more depth on this subject.