Super() In Java Example
Chapter:
Inheritance
Last Updated:
14-07-2016 11:52:10 UTC
Program:
/* ............... START ............... */
class Parent {
int k = 10;
}
public class JavaSuperExample extends Parent{
public void superCalling()
{
// User of super
System.out.println(super.k);
}
public static void main(String args[]){
JavaSuperExample superExample = new JavaSuperExample();
superExample.superCalling();
}
}
/* ............... END ............... */
Output
Notes:
-
Super is used to call the constructor, methods and properties of parent class.
- Super is used to refer immediate parent class instance variable.
- super.(variable_name) refers to the variable of variable of parent class.
- super() invokes the constructor of immediate parent class.
- super.(method_name) refers to the method of parent class.
Tags
Super() In Java, Java