Java Keyword Super

The reserved keyword super is used to access members of a class inherited by the class in which it appears. The super keyword is also used to forward a call from a constructor to a constructor in the superclass.

The sample Java code below first defines a base class and then defines a sub class that extends the class. The sub class uses the super keyword to not only access the variable but also the method of the base class.

//JavaCodeDepot Sample 

public class JavaCodeDepotSuper {

    protected short jcdShort;
     
    protected showShort() {

        System.out.println("jcdShort="+jcdShort);
    }
}
 
public class JavaCodeDepotSub extends JavaCodeDepotSuper {

    void randomJCDFunction() {

        super.jcdShort = 10000;

        super.showShort();
    }
}


One of the important concepts of Java programming is polymorphism. You can continue reading up on polymorphism from our explanation page.

The complete list of Java reserved keywords contains a total of 50 keywords and 3 literal words that are unable to be used as variable names.

Add a Comment

Your email address will not be published. Required fields are marked *