by BehindJava

What is super keyword in java

Home » java » What is super keyword in java

In this tutorial we are going to learn about super keyword in java.

Super keyword in java is a reference which is used to refer immediate parent class object.

Using super keyword, we can refer immediate parent class instance variable and immediate parent class method can be invoked and also invoke immediate parent class constructor.

Note: super keyword is provided by the compiler implicitly.

Sample Code Snippet:

public class Parent
{
	Parent()
	{
		System.out.println("PARENT CLASS");
	}
	
}
public class Child extends Parent
{
     Child()
     {
    	 System.out.println("CHILD CLASS");
     }
   public static void main(String[] args)
   {
	   Child c=new Child();
   }
}

Output:
PARENT CLASS
CHILD CLASS

Also refer to this tutorial for usage of super keyword with interfaces.