In Java, the super keyword is used to access variables and methods of a super class from a sub class. For example:

public class Super {
    protected int number;
    
    protected showNumber() {
        System.out.println("number = " + number);
    }
}

public class Sub extends Super {
    void bar() {
        super.number = 10;
        super.showNumber();
    }
}

In the above example, the class Sub accesses the variable number and calls the method showNumber() for its super class Super.

Related keyword: this. See all keywords in Java.

  

Other Recommended Tutorials:


About the Author:

is certified Java programmer (SCJP and SCWCD). He began programming with Java back in the days of Java 1.4 and has been passionate about it ever since. You can connect with him on Facebook and watch his Java videos on YouTube.



Add comment

   


Comments 

#2SAM2017-09-11 07:16
class Super {
protected int number;
protected void showNumber(){
System.out.println("numer : " +number);
}
}

public class SubClassTest extends Super {
void bar(){
super.number =10;
super.showNumber();
}
public static void main(String[]args) {
SubClassTest obj = new SubClassTest();
obj.bar();
}
}
Quote
#1ARUN REDDY2017-09-10 06:45
SEND THE "THIS ,STATIC,SUPER KEYWORDS
Quote