Site icon TestingDocs.com

Java super Keyword with Example

Overview

In this tutorial, we will learn about the super keyword in Java. In the previous post, we learned about this keyword.

super is a reference variable that points to the superclass object. We can use this keyword in a subclass to refer to the parent methods, variables, and constructors.

Example

package staff;

// Constructor
public class SalaryEmployee extends Staff {
	private double empSalary;

	//Constructor
	public SalaryEmployee(String name, String address,double salary) {
		super(name, address);
		this.empSalary = salary;
	}

}

Notice how we have invoked the Parent class constructor using the super keyword.

super(name, address);

Java Tutorial on this website:

https://www.testingdocs.com/java-tutorial/

For more information on Java, visit the official website :

https://www.oracle.com/java/

Exit mobile version