super() method in java | Core Java Tutorials

This Core Java Tutorials “super() method in java” explains clearly what is super() method in java and how to access Parent class constructor using super() to initialize Parent’s Object in Java.


 

super():

  • Used to access Parent class constructor from the child class.
  • We must use super() method only inside the constructor of Child class.
  • Call to super() method must be the first statement in the Child’s constructor.

 

Note:

  • JVM instantiates Parent class in the process of Child object creation.
  • JVM invokes Parent class default constructor using super() method.
  • JVM always invokes zero args constructor only implicitly.

 

Parent Object initialization:

  • We cannot access Parent’s constructor in Inheritance concept.
  • Hence we cannot initialize Parent’s object directly.
  • Using super() method, we can invokes parent’s constructor to pass initial values.
  • Following example explains clearly how to provide initialization to Parent Object in inheritance

 

Initialize Parent and Child object at a time:

 

Share this