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

10

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

Similar Programs Chapter Last Updated
Java Final Class Inheritance 02-08-2017
Java Final Method In Inheritance Inheritance 02-08-2017
Java Multilevel Hierarchical Inheritance Inheritance 01-08-2017
Java Super To Invoke Parent Class Method Inheritance 31-07-2017
Java Super To Invoke Parent Class Constructor Inheritance 30-07-2017
Static And Dynamic Binding In Java Inheritance 24-03-2017
Java Overloaded Method To Print Array Inheritance 03-09-2016
Dynamic Method Dispatch In Java Example Inheritance 19-06-2016
Abstract Class In Java Example Inheritance 20-07-2016
Method Overriding In Java Example Inheritance 20-07-2016
Method Overloading In Java Example Inheritance 20-07-2016
Inheritance And Constructors In Java Inheritance 20-07-2016
Multilevel Inheritance In Java Example Inheritance 22-09-2018
Inheritance In Java Example Inheritance 20-07-2016

1