What is super in java?

The super keyword in Java is a reference variable that is used to refer to the immediate parent class object. Whenever you create the instance of the subclass, an instance of the parent class is created implicitly which is referred by super reference variable. The super() is called in the class constructor implicitly by the compiler if there is no super or this.

  1. class Animal{
  2. Animal(){System.out.println(“animal is created”);}
  3. }
  4. class Dog extends Animal{
  5. Dog(){
  6. System.out.println(“dog is created”);
  7. }
  8. }
  9. class TestSuper4{
  10. public static void main(String args[]){
  11. Dog d=new Dog();
  12. }
  13. }


animal is created
dog is created