---
title: "super keyword in java"  
description: "The super keyword in java is a reference variable that is used to refer immediate parent class object."  
author: "Manoj Pandey"  
published: 2015-04-24  
updated: 2017-12-06  
canonical: https://www.mindstick.com/articles/1744/super-keyword-in-java  
category: "java"  
tags: ["java"]  
reading_time: 2 minutes  

---

# super keyword in java

The [super keyword](https://answers.mindstick.com/qa/92536/what-is-the-super-keyword) in java is a [reference](https://www.mindstick.com/forum/34619/call-by-value-and-call-by-reference) variable that is used to refer [immediate](https://answers.mindstick.com/qa/96807/tadarise-immediate-informal-solution-of-ed-in-men) parent class object. If your method overrides one of its superclass's methods, you can invoke the overridden method through the use of the keyword super. You can also use super to refer to a hidden field (although hiding fields is discouraged). Consider this class, Superclass:\

In Java 'super' keyword can be used to refer superclass [instance](https://www.mindstick.com/forum/155658/testing-connection-to-cloud-sql-instance-with-a-mysql-client-from-vm-instance) in a subclass.

In Java 'super' keyword can be used to refer superclass instance in a subclass.

##### Super keyword is used for two different purpose.

1. To call the Super class constructor

Super keyword is used to execute the super class constructor in [sub class](https://answers.mindstick.com/qa/92538/what-are-the-base-class-sub-class-and-superclass) constructor.

Example of super keyword to call constructor of super class in sub class

```
class Person{   Person()    {      System.out.println("Constructor of person class");     }}  class Employee extends Person{     Employee()     {     System.out.println("Constructor of employee class");      }} class PermanentEmployee extends Employee{     PermanentEmployee()     {       System.out.println("Constructor of permanent employee class");      }} class ConstructorInheritanceDemo{      public static void main(String args())      {               PermanentEmployee pObj = new PermanentEmployee();       }}
```

##### Output-:

Constructor of person class

Constructor of [employee](https://www.mindstick.com/articles/178134/how-to-write-the-best-welcome-letter-for-new-employees) class

Constructor of [permanent](https://answers.mindstick.com/qa/50600/what-is-a-permanent-storage-in-pc) employee class

##### 2. To execute super class method

The super keyword can also be used to invoke parent [class method](https://www.mindstick.com/interview/22908/what-are-java-string-class-method). It should be used in case subclass contains the same [method as](https://www.mindstick.com/forum/159054/how-to-mark-a-method-as-obsolete-or-deprecated-in-c-sharp) parent class as in the example given below:

```
class Parentclass {      // Overridden method      void display() {            System.out.println("Parent class method");      }} class Subclass extends Parentclass {      // Overriding method      void display() {            System.out.println("Child class method");      }       void printMsg() {            // This would call Overriding method            display();            // This would call Overridden method            super.display();      }       public static void main(String args[]) {            Subclass obj = new Subclass();            obj.printMsg();      }}
```

##### \

##### Output:

welcome to java

welcome

---

Original Source: https://www.mindstick.com/articles/1744/super-keyword-in-java

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
