Core Java SQL Oracle PHP Examples JSP JDBC MORE

Java Super Keyword


Super is a reference variable that is used to references parent class object.

Use of super keyword

Super() is used to invoke parent class constructor,method,variable

Syntax of Super Keyword

super.method-name();

Example

lass Fruit{
String color="green";
}
class Apple extends Fruit{
String color="pink";
void printColor(){
System.out.println(color);
System.out.println(super.color);
}
}
class TestSuper1{
public static void main(String args[]){
Apple c=new Apple();
c.printColor();
}
}

Output :
green
pink