Summarise With AI
ChatGPT
Perplexity
Claude
Gemini
Grok
ChatGPT
Perplexity
Claude
Gemini
Grok
Back

Super Keyword in Java: Usage with Examples

22 Nov 2025
5 min read

Key Takeaways From the Blog

  • Super​‍​‌‍​‍‌​‍​‌‍​‍‌ keyword refers to the parent class that is one level up in the hierarchy. To this end, gaining direct access to inherited members through subclasses and keeping the correct working of the inheritance chain is the main aim of using the super keyword by subclasses.
  • When a child class redefines or conceals members of the parent class, the super keyword can still be used to refer to parent class variables, methods, and constructors.
  • The super keyword changes (resolves) naming and behavior conflicts. Moreover, it helps to recognize the parent members when there is shadowing of variables or overriding of methods, i.e., child members are used in these cases.
  • With the help of super keyword, it is possible to call the parent constructor first thus ensuring constructor chaining, which, in turn, is a prerequisite of stable object creation.
  • Besides that, Java's encapsulation regulations are observed by the super keyword which cannot be used for accessing the private members of the superclass yet it still allows controlled access to the inherited features.
  • Using the keyword super is a must for inheritance that is well organized, code reuse, and polymorphism as it is of great help to developers who want to extend base functionality without writing the same code twice or having an unclear ​‍​‌‍​‍‌​‍​‌‍​‍‌situation.

Introduction

Java's​‍​‌‍​‍‌​‍​‌‍​‍‌ super keyword is a reference variable that helps you get members (variables, methods, or constructors) of a parent class that you have from a subclass. It is the primary mechanism for inheritance, guiding subclasses to use inherited members and resolve conflicts between overridden methods and variables. With super, programmers are able to call the methods of the parent class, get access to the hidden variables, and call the constructors for making sure child classes are properly initialized and work as expected.

The article is about different ways the super keyword can be used in Java with the help of which you can understand the significance of method overriding, constructor chaining, and dealing with inheritance ​‍​‌‍​‍‌​‍​‌‍​‍‌hierarchies.

What is a Super Keyword in Java?

The super keyword is a type of reference that refers to the direct parent class object. It is used to call the parent class's methods, variables, and constructors. The super keyword is accessed primarily via inheritance to call inherited parent class members whenever overridden or hidden by the child class, with appropriate access to inherited behaviours and attributes.

Usage

There are three ways to use of super keyword in java:

  • Use of super with Variables
  • Use of super with Methods
  • Use of super with Constructors

Examples of Super Keyword in Java

Here are the examples of super keyword in Java such as:

1. Use of super with Variables

The super keyword can be used to reference parent class instance variables in case the names of parent class members and child class members conflict.

Syntax

super.variableName;

Example Code

Here is the Java program for super keyword using variables:

class Animal {
    String sound = "Some sound";
}

class Dog extends Animal {
    String sound = "Bark";
    
    void printSound() {
        System.out.println("Child class sound: " + sound);
        System.out.println("Parent class sound: " + super.sound);
    }
}

public class TestSuper {
    public static void main(String[] args) {
        Dog dog = new Dog();
        dog.printSound();
    }
}

Explanation

  • The Dog class inherits from the Animal class.
  • Both classes have a sound variable, but the child class Dog overrides it.
  • Using super.sound accesses the sound variable from the parent Animal class, while just sound refers to the variable from the child class.

Output

Child class sound: Bark
Parent class sound: Some sound

Key Takeaways So Far

  • The​‍​‌‍​‍‌​‍​‌‍​‍‌ keyword super is used for resolution of shadowing of variables in the case when a parent and a child have variables with the same names.
  • Thus it is guaranteed that the fields of the superclass will be accessed correctly.
  •  Supports clarity and comfort of reading by inheritance without any ambiguities.
  • Helpful in situations when the functionality is being extended and the parent attributes are ​‍​‌‍​‍‌​‍​‌‍​‍‌kept.

2. Use of super with Methods

The super keyword is used to call the parent class's method when the method is overridden in the child class.

Syntax

super.methodName();

Example Code

Here is the java program for super keyword using methods:

class Animal {
    void makeSound() {
        System.out.println("Animal makes sound");
    }
}

class Dog extends Animal {
    void makeSound() {
        System.out.println("Dog barks");
    }
    
    void callParentSound() {
        super.makeSound();  // Calling parent class method
    }
}

public class TestSuper {
    public static void main(String[] args) {
        Dog dog = new Dog();
        dog.makeSound();        // Child class method
        dog.callParentSound();  // Parent class method using super
    }
}

Explanation

  • The​‍​‌‍​‍‌​‍​‌‍​‍‌ Dog class calls the Animal constructor with super(name), thereby forwarding the name parameter.
  • Hence, the parent class constructor gets the chance to set up the parent class portion of the ​‍​‌‍​‍‌​‍​‌‍​‍‌object.

Output

Dog barks
Animal makes sound

Quick Note: The super.method() enables subclasses to reuse and augment superclass behaviors during method overriding.

3. Use of super with Constructors

The super constructor in java calls a parent class constructor using the super keyword. This is particularly helpful when the parent class has a parameterized constructor, and you wish to call it from the child class.

Syntax

super();
super(parameters);

Example Code

Here is the Java super example using constructors:

class Animal {
    Animal(String name) {
        System.out.println("Animal name: " + name);
    }
}

class Dog extends Animal {
    Dog(String name) {
        super(name);  // Calling parent class constructor
        System.out.println("Dog name: " + name);
    }
}

public class TestSuper {
    public static void main(String[] args) {
        Dog dog = new Dog("Buddy");
    }
}

Explanation

  • The Animal constructor is invoked by the Dog class with super(name), passing in the name parameter.
  • This allows the parent class constructor to initialize the parent class part of the object.

Output

Animal name: Buddy
Dog name: Buddy

Quick Recap: The super() triggers superclass constructor execution, ensuring correct initialization order across inheritance layers.

Characteristics and Best Practices of the Super Keyword in Java

Understanding the key characteristics for using the super keyword effectively in Java is essential for writing robust, maintainable code that leverages inheritance, polymorphism, and constructor overloading.

Key Characteristics of the super Keyword

  • Supports Inheritance in Java: The super keyword enables subclasses to access members (methods and variables) and constructors of their immediate superclass, making it fundamental to inheritance in Java.
  • Constructor Chaining and Default Constructor: The super() call is used for constructor chaining, ensuring the superclass is initialized before the subclass. If not explicitly specified, Java inserts a call to the default constructor of the superclass.
  • Resolves Ambiguity: When subclass members (variables or methods) hide those of the superclass, super helps avoid ambiguity and ensures the correct member is accessed.
  • Facilitates Polymorphism: By allowing access to overridden methods in the superclass, super supports polymorphic behavior and method resolution.
  • Cannot Access Private Members: The super keyword cannot be used to access private fields or methods of the superclass.

Best Practices for Using super Keyword

  • Always​‍​‌‍​‍‌​‍​‌‍​‍‌ Place super() as the First Statement: If you are moving up a level to a superclass constructor from a subclass, then it is super(), or super(parameters), that should be the very first statement in the constructor. This is the main thing for the correct object setup, particularly, when constructor overloading is involved.
  • Use super to Enhance, Not Replace: In case you have overridden methods, employ super.methodName() to continue the base behavior rather than completely substituting it, unless a total override is the only case.
  • Don't Overuse super: Emphasize with super only in situations where it is necessary to solve conflicts or gain access to superclass functionalities. If not required, using super can make the code less readable and lower in maintainability.
  • Constructor Overloading Considerations: Ensure that the subclass uses the correct super() call when it decides to invoke the overloaded constructor of the superclass.
  • Practical Examples: Use real-life examples in your code to demonstrate the usage of the super keyword effectively, such as solving variable shadowing or extending methods of a ​‍​‌‍​‍‌​‍​‌‍​‍‌superclass.

Quick Points to Remember

  • If the superclass does not have a default constructor and the subclass does not explicitly call a superclass constructor, a compile-time error will occur.
  • The super cannot be used in static contexts.
  • Use super judiciously to maintain clear and understandable inheritance hierarchies.

Advantages of Super Keyword Usage in Java

Here are the advantages of super keyword usage in Java:

  • Prevents​‍​‌‍​‍‌​‍​‌‍​‍‌ Name Conflicts: One of the ways advanced keyword helps is by showing which method or variable of the parent or the child class has the same name.
  • Parent Class Method Access: When the child class wants to use a method of the parent class, especially in the case of overriding, it is super that helps.
  • Constructor Chaining: Proper setup with the constructor of the parent class is possible with the help of super keyword.
  • Code Reusability: Allows the use of parent class variables and methods without copying the ​‍​‌‍​‍‌​‍​‌‍​‍‌code.
  • Clean Hierarchical Structure: Permits preventing ambiguity in the inheritance chain by directly accessing the parent class.
  • Ensures Inheritance Integrity: Prevents the wrong method or constructor from being invoked, maintaining the parent class behaviour.

Quick Note: The super keyword improves clarity, prevents conflicts, supports reuse, and ensures proper initialization—making inheritance safer, cleaner, and more predictable in Java applications.

Important Points to Remember While Using Super Keyword in Java

Here are the important points to remember while using super keyword in Java such as:

  • Call​‍​‌‍​‍‌​‍​‌‍​‍‌ to super() Should Be the First Statement: A call to super() (or a call to the parent constructor) in a constructor of a subclass should be the first statement. This is to make sure that the parent class is called first before the subclass, thus keeping the correct order of ​‍​‌‍​‍‌​‍​‌‍​‍‌inheritance.
  • Default Constructor Call: If none of the constructors call an explicit superclass constructor, the Java compiler will automatically insert a call to the superclass no-argument constructor. If no no-argument constructor exists in the superclass, it will be a compile-time error.
  • Constructor Chaining: When a subclass constructor calls the superclass constructor explicitly or indirectly, it creates a chain of calls to the constructors, ending in invoking the Object class constructor, which is the topmost class in Java.
  • Cannot Access Private Members: The Java keyword super cannot call the private members of the parent class.
  • Object Initialization: The superclass constructor has already initialized the object when it calls the subclass constructor so that parent class fields are appropriately initialised.
  • Constructor Chaining Across Multiple Levels: When the superclass provides a constructor chain, it could make several calls but eventually trace back to the Object as its base superclass.
  • Overridden Methods: The super keyword is used when you want to call an overridden method of the parent class in the child class.

Bottom Line: Proper usage of super keeps the program free from errors during initialization, plays by the inheritance rules, and allows methods to be resolved correctly without the need for breaking encapsulation or the class ​‍​‌‍​‍‌​‍​‌‍​‍‌structure. 

Conclusion

In conclusion, the super keyword in Java is a powerful tool for referencing parent class members. It is primarily used to call parent class methods, constructors, and variables and is one of the primary tools for dealing with inheritance in Java. The super keyword facilitates code reusability and assists in method overriding and constructor chaining.

Why It Matters?

Grasping the use of super keyword is a must when you want to write clean, easy-to-understand Java code that properly uses inheritance. It is the key to correct object creation, avoids naming conflicts, supports polymorphism, and allows extending a method without copying it. By mastering super, developers can create class hierarchies that are stable, can grow with the project, and are free from the most common inheritance mistakes. 

Practical Advice for Learners

  • Use super() intentionally—never as an afterthought.
  • If you just want to change the behavior of a method, call the parent's method and then add your code there.
  • Work on examples where you have variable shadowing and constructor chaining.
  • Get to know the situations where there are errors because the parent constructors are ​‍​‌‍​‍‌​‍​‌‍​‍‌missing. 

Frequently Asked Questions

1. What is the super keyword in Java?

The super keyword is used in a subclass to refer to its immediate superclass. It allows access to superclass methods, variables, and constructors, especially when they are hidden or overridden by the subclass. The syntax commonly used is super.methodName(), super.variableName, or super().

2. How does the super() constructor work?

The super() constructor is used in a subclass constructor to explicitly call a constructor of its superclass. This is essential for proper object initialization and constructor chaining, a concept especially important in inheritance hierarchies. According to Java SE 9 and later, if you do not explicitly call a superclass constructor, the compiler automatically inserts a no-argument super() call.

3. Can you explain the difference between this keyword and super keyword?

The this keyword refers to the current instance of the class and is used to access its own members, while the super keyword is used to access members of the immediate superclass. For example, this() can call another constructor in the same class, whereas super() calls a constructor of the superclass.

4. When should I use super in method overriding?

In method overriding, a subclass provides its own implementation of a method already defined in its superclass. To invoke the superclass version of the method from the subclass, use super.methodName(). This is helpful when you want to extend or supplement the original functionality rather than completely replace it.

5. How does the super keyword relate to abstraction, encapsulation, and polymorphism?

  • Abstraction: By allowing subclasses to call and extend superclass methods, super supports abstraction by letting you define general behavior in a superclass and specialized behavior in subclasses.
  • Encapsulation: Super helps maintain encapsulation by granting controlled access to superclass members, without exposing their internal implementation.
  • Polymorphism: Super is fundamental in polymorphic behavior, especially when overridden methods are involved, as it allows subclasses to invoke superclass methods as needed.

6. Can I use super to access private members of the superclass?

No, the super keyword cannot be used to access private variables or methods of the superclass. Private members are only accessible within the class they are declared.

7. Is it mandatory to use super() in the subclass constructor?

It is not mandatory to explicitly use super() unless you need to call a parameterized constructor of the superclass. If omitted, the Java compiler automatically inserts a call to the no-argument constructor of the superclass.

8. Can super be used in static contexts?

No, the super keyword cannot be used in static methods or static blocks, as it requires an instance context to refer to the superclass.

9. What happens if the superclass does not have a no-argument constructor?

If the superclass does not have a no-argument constructor and the subclass does not explicitly call a superclass constructor using super(), a compile-time error will occur.

10. How does the super keyword support inheritance and code reusability?

The super keyword is a core feature of inheritance. It enables subclasses to reuse and extend the functionality of their superclasses, supporting cleaner code, reduced duplication, and a more maintainable hierarchy.

Read More Articles

Chat with us
Chat with us
Talk to career expert