Topic 69 of 119 6. Object-Oriented Programming in Java Interactive Tutorial

The super Keyword in Java: Parent Class Access and Method Calls

9 mins read Last updated: 22 Aug 2026 26,937 views

Direct Answer & Core Concept

When you start learning Java inheritance, you will often work with a parent class and a child class. Sometimes the child class has its own method or variable, but you still need to use something from the parent class.

This is where the super keyword in Java becomes useful.

The super keyword allows a subclass to refer to its immediate parent class. You can use it to call a parent constructor, access a parent variable, or run a parent method.

For beginners, the easiest way to remember it is:

super means “go to my immediate parent class.”

For example, if Dog extends Animal, then super inside Dog refers to Animal.

Main.java
Run Online
class Animal {
    void eat() {
        System.out.println("Animal is eating");
    }
}class Dog extends Animal {
    void show() {
        super.eat();
    }
}

Here, super.eat() tells Java to use the eat() method from the parent class.


Detailed Explanation & Mechanics

What Is the super Keyword in Java?

The super keyword in Java is used inside a subclass to refer to its immediate superclass.

It is mainly useful when the child class needs to access something specifically defined in its parent class.

Java provides three common uses of super:

  1. super() – calls the parent class constructor.

  2. super.methodName() – calls a parent class method.

  3. super.variableName – accesses a parent class variable.

These three forms look similar, but they solve different problems.

Simple Example

Main.java
Run Online
class Vehicle {
    String type = "Vehicle";
    void start() {
        System.out.println("Vehicle is starting");
    }
}class Car extends Vehicle {
    void display() {
        System.out.println(super.type);
        super.start();
    }
}

In this example:

  • super.type accesses the parent variable.

  • super.start() calls the parent method.


Why Do We Need super in Java?

You may wonder why Java needs the super keyword when a child class already inherits members from its parent.

In many simple situations, you do not need to write super.

However, problems can appear when the child class has a member with the same name as the parent, or when the child overrides a parent method.

For example:

Main.java
Run Online
class Employee {
    String name = "Rahul";
}class Manager extends Employee {
    String name = "Amit";
    void showNames() {
        System.out.println(name);
        System.out.println(super.name);
    }
}

Output:

The first name refers to the child class variable.

The super.name expression specifically refers to the parent class variable.

So, super is useful when you want to remove confusion between parent and child members.


Uses of super Keyword in Java

The super keyword is mainly used in three ways.

SyntaxPurpose
super()Calls the parent class constructor
super.method()Calls the parent class method
super.variableAccesses the parent class variable

Let's understand each one with simple examples.


1. Calling the Parent Class Constructor Using super()

A constructor is used when an object is created.

When a child object is created, the parent part of that object must also be initialized. Java handles this parent initialization through constructor calls.

You can explicitly call a parent constructor using:

or:

The super() statement must be the first statement inside a constructor.

Example of super() in Java

Main.java
Run Online
class Animal {
    Animal(String type) {
        System.out.println("Animal type: " + type);
    }
}class Dog extends Animal {
    Dog() {
        super("Dog");
        System.out.println("Dog object created");
    }
}public class Main {
    public static void main(String[] args) {
        Dog dog = new Dog();
    }
}

Output

Main.java
Run Online
Animal type: DogDog object created

How does this work?

When this line runs:

Java starts executing the Dog constructor.

The first statement is:

That calls the constructor of Animal.

After the parent constructor finishes, the remaining statements in the Dog constructor execute.

So the order is:

Main.java
Run Online
Dog object created↓Dog constructor starts↓super("Dog")↓Animal constructor↓Dog constructor continues

Why Is super() Important in Constructor Chaining?

Constructor chaining means one constructor calls another constructor as part of object initialization.

With inheritance, super() can connect the child constructor to a constructor in the parent class.

For example:

Main.java
Run Online
class Person {
    Person(String name) {
        System.out.println("Name: " + name);
    }
}class Student extends Person {
    Student(String name) {
        super(name);
        System.out.println("Student created");
    }
}

Here:

passes the value from the child constructor to the parent constructor.

This is useful when the parent class is responsible for initializing common information.

The reference material also highlights constructor chaining as one of the important situations where super() is used.


What Happens If You Do Not Write super()?

If you do not explicitly write a super() call in a subclass constructor, Java tries to insert a call to the parent class's no-argument constructor automatically.

For example:

Main.java
Run Online
class Animal {
    Animal() {
        System.out.println("Animal constructor");
    }
}class Dog extends Animal {
    Dog() {
        System.out.println("Dog constructor");
    }
}

Conceptually, Java treats the child constructor as if it contained:

Main.java
Run Online
Dog() {
    super();
    System.out.println("Dog constructor");
}

This automatic behavior works when the parent class has an accessible no-argument constructor.

If the parent class only has a parameterized constructor, the child constructor must explicitly call an appropriate parent constructor.

Example:

Main.java
Run Online
class Animal {
    Animal(String name) {
        System.out.println(name);
    }
}class Dog extends Animal {
    Dog() {
        super("Rocky");
    }
}

Without the explicit super("Rocky"), the code would not compile because Java would try to call Animal() and that constructor does not exist.


2. Calling the Parent Class Method Using super

Another important use of super is calling a method from the parent class.

This becomes especially useful when the child class overrides a method.

Suppose the parent has a method called sound():

Main.java
Run Online
class Animal {
    void sound() {
        System.out.println("Animal makes a sound");
    }
}

The child class can override it:

Main.java
Run Online
class Dog extends Animal {
    @Override void sound() {
        System.out.println("Dog barks");
    }
}

Normally, calling:

runs the child version.

But what if the child also wants to execute the original parent behavior?

Use:


Java super Keyword with Method Overriding

Here is a complete example:

Main.java
Run Online
class Animal {
    void sound() {
        System.out.println("Animal makes a sound");
    }
}class Dog extends Animal {
    @Override void sound() {
        super.sound();
        System.out.println("Dog barks");
    }
}public class Main {
    public static void main(String[] args) {
        Dog dog = new Dog();
        dog.sound();
    }
}

Output

Main.java
Run Online
Animal makes a soundDog barks

The statement:

runs the parent version first.

Then:

Main.java
Run Online
System.out.println("Dog barks");

adds the child-specific behavior.

This is one of the most practical uses of the Java super keyword.


Why Use super with Method Overriding?

Using super.methodName() is useful when you do not want to completely replace the parent behavior.

For example, imagine a parent class performs common logging:

Main.java
Run Online
class Account {
    void openAccount() {
        System.out.println("Account opened");
    }
}

A child class can add its own behavior:

Main.java
Run Online
class SavingsAccount extends Account {
    @Override void openAccount() {
        super.openAccount();
        System.out.println("Savings account features enabled");
    }
}

The child gets the original parent behavior and then adds something extra.

This approach can prevent unnecessary duplication of code.

The source material similarly identifies reusing parent logic inside an overridden method as a common reason to use super.


3. Accessing a Parent Class Variable Using super

A child class can have a variable with the same name as a variable in its parent.

This is called field hiding or variable shadowing.

In that situation, super.variableName lets you access the parent version.

Example

Main.java
Run Online
class Animal {
    String name = "Animal";
}class Dog extends Animal {
    String name = "Dog";
    void display() {
        System.out.println("Child name: " + name);
        System.out.println("Parent name: " + super.name);
    }
}public class Main {
    public static void main(String[] args) {
        Dog dog = new Dog();
        dog.display();
    }
}

Output

Main.java
Run Online
Child name: DogParent name: Animal

Here:

refers to the variable declared in Dog.

But:

refers to the variable declared in Animal.


Difference Between name and super.name

This is an important point for beginners.

Suppose:

Main.java
Run Online
class Parent {
    String value = "Parent";
}class Child extends Parent {
    String value = "Child";
    void show() {
        System.out.println(value);
        System.out.println(super.value);
    }
}

The result is:

Think of it like this:

Main.java
Run Online
value↓Current class → Childsuper.value↓Immediate parent → Parent

The super keyword removes the ambiguity.


super with Method Overriding vs Variable Hiding

Methods and variables behave differently in Java, so it is useful to keep the two cases separate.

Parent method

Calls the parent implementation of the method.

Parent variable

Reads the parent class field.

For methods, super is particularly useful when the child overrides a method.

For fields, super is useful when the child declares a field with the same name.


super in Multi-Level Inheritance

Java supports inheritance across multiple levels.

For example:

Here:

  • Animal is the grandparent class.

  • Dog is the parent of Puppy.

  • Puppy is the child class.

One important rule is that super refers to the immediate parent, not directly to any class farther up the hierarchy.

For example:

Main.java
Run Online
class Animal {
    void eat() {
        System.out.println("Animal eats");
    }
}class Dog extends Animal {
    void bark() {
        System.out.println("Dog barks");
    }
}class Puppy extends Dog {
    void show() {
        super.bark();
    }
}

Here:

refers to Dog, because Dog is the immediate parent of Puppy.

It does not directly mean Animal.

The source material also notes that in multi-level inheritance, super refers to the immediate parent class.


Can super Access Private Members?

No.

A child class cannot directly access private fields or private methods of its parent class using super.

For example:

Main.java
Run Online
class Parent {
    private int number = 10;
}class Child extends Parent {
    void show() {
        // System.out.println(super.number); // Error
    }
}

The variable number belongs only to the private scope of Parent.

If the parent wants to expose that value, it can provide a method:

Main.java
Run Online
class Parent {
    private int number = 10;
    int getNumber() {
        return number;
    }
}

Then the child can call:

Main.java
Run Online
class Child extends Parent {
    void show() {
        System.out.println(super.getNumber());
    }
}

So, super does not bypass Java's access control rules. The reference source also explicitly notes that private parent members cannot be accessed directly through super.


Can We Use super in a Static Method?

No.

The super keyword is associated with the current object and its parent class. A static method belongs to the class rather than a particular object.

Therefore, Java does not allow super inside a static method.

For example:

Main.java
Run Online
class Parent {
    void show() {
        System.out.println("Parent");
    }
}class Child extends Parent {
    static void test() {
        // super.show(); // Compile-time error
    }
}

If you need to use super, place the code in an instance method or constructor.

The provided reference also identifies static methods as a situation where super cannot be used.


Can We Use super() and this() Together?

No.

Inside one constructor, you cannot directly use both:

and:

Both constructor calls must appear as the first statement, so Java does not allow them together in the same constructor.

For example, this is invalid:

Main.java
Run Online
class Child extends Parent {
    Child() {
        this(10);
        super();
    }
}

Instead, you normally choose one constructor call.

this()

Calls another constructor in the same class.

super()

Calls a constructor in the immediate parent class.

The reference source also identifies this as an important rule for Java constructors.


super() vs this()

Beginners often confuse these two keywords.

KeywordUsed forExample
this()Calls another constructor in the same classthis(10);
super()Calls a constructor in the parent classsuper(10);
this.nameRefers to current class fieldthis.name
super.nameRefers to parent class fieldsuper.name
this.show()Calls current class methodthis.show()
super.show()Calls parent class methodsuper.show()

A simple memory trick:

Main.java
Run Online
this → current classsuper → parent class

A Complete Example of super in Java

Let's combine the main concepts into one example.

Main.java
Run Online
class Employee {
    String name;
    Employee(String name) {
        this.name = name;
    } void work() {
        System.out.println("Employee is working");
    }
}class Developer extends Employee {
    String name;
    Developer(String name) {
        super(name);
        this.name = name;
    } @Override void work() {
        super.work();
        System.out.println("Developer is writing code");
    } void showNames() {
        System.out.println("Developer name: " + name);
        System.out.println("Employee name: " + super.name);
    }
}public class Main {
    public static void main(String[] args) {
        Developer developer = new Developer("Amit");
        developer.work();
        developer.showNames();
    }
}

Output

Main.java
Run Online
Employee is workingDeveloper is writing codeDeveloper name: AmitEmployee name: Amit

This example demonstrates:

calling the parent constructor.

calling the parent method.

accessing the parent field.


How super Works During Object Creation

When you create a child object, Java initializes the parent part before completing the child constructor.

Consider:

Main.java
Run Online
class Parent {
    Parent() {
        System.out.println("Parent constructor");
    }
}class Child extends Parent {
    Child() {
        super();
        System.out.println("Child constructor");
    }
}

Creating the object:

produces:

Main.java
Run Online
Parent constructorChild constructor

The parent constructor runs first.

You can visualize the process like this:

Architecture Diagram
Create Child object
       │
       ▼
Call Child constructor
       │
       ▼
super()
       │
       ▼
Parent constructor
       │
       ▼
Return to Child constructor
       │
       ▼
Child initialization

This is why parent initialization happens before child-specific constructor code.


When Should You Use super in Java?

You do not need to use super everywhere.

Use it when the code actually needs to refer to the parent class.

Use super() when:

  • The child constructor needs to call a specific parent constructor.

  • The parent class requires values during initialization.

  • You want clear constructor chaining.

Use super.method() when:

  • A child overrides a parent method.

  • You want to keep the original parent behavior.

  • You want to add child-specific behavior after parent logic.

Use super.variable when:

  • Parent and child fields have the same name.

  • You need the value stored in the parent field.

  • You want to make the source of a field explicit.


Common Mistakes With the super Keyword

1. Putting super() after another statement

This is incorrect:

Main.java
Run Online
Child() {
    System.out.println("Hello");
    super();
}

super() must be the first statement in the constructor.

Correct:

Main.java
Run Online
Child() {
    super();
    System.out.println("Hello");
}

2. Trying to use super in a static method

This is not allowed:

Main.java
Run Online
static void test() {
    // super.show();
}

super requires an instance context.


3. Using super to access private fields

This does not work:

Main.java
Run Online
class Parent {
    private int age = 30;
}class Child extends Parent {
    void show() {
        // System.out.println(super.age);
    }
}

Use an accessible method such as a getter instead.


4. Thinking super means any ancestor

super refers to the immediate parent class.

If the hierarchy is:

Inside C:

refers to B, not directly to A.


5. Confusing super with this

Remember:

Main.java
Run Online
this = current classsuper = immediate parent class

This simple distinction solves many beginner mistakes.


Advantages of Using super in Java

The super keyword makes inheritance code easier to manage in several situations.

1. Reuse parent functionality

You can call an existing parent method instead of writing the same code again.

2. Avoid naming confusion

super.name clearly identifies the parent field.

3. Support constructor chaining

super() connects a child constructor with a parent constructor.

4. Extend overridden methods

A child can run parent logic and then add its own behavior.

5. Make inheritance easier to understand

When reading code, super clearly tells you that the operation belongs to the parent class.


Quick Difference: super() vs super.method() vs super.variable

These three forms are worth memorizing.

Calls the parent constructor.

Calls the parent method.

Accesses the parent field.

A quick visual:

Architecture Diagram
                 super
                   │
       ┌───────────┼───────────┐
       │           │           │
       ▼           ▼           ▼
    super()   super.method()  super.variable
       │           │           │
       ▼           ▼           ▼
  Constructor    Method       Field

Real-World Example of super

Imagine an application with different types of employees.

The parent class contains common employee behavior:

Main.java
Run Online
class Employee {
    void login() {
        System.out.println("Employee logged in");
    }
}

A developer class extends it:

Main.java
Run Online
class Developer extends Employee {
    @Override void login() {
        super.login();
        System.out.println("Developer dashboard opened");
    }
}

When:

Main.java
Run Online
Developer developer = new Developer();
developer.login();

runs, the output is:

Main.java
Run Online
Employee logged inDeveloper dashboard opened

The parent handles the common login process.

The child then adds its own behavior.

This pattern is useful in applications where several child classes share common functionality but also need their own specific logic.


Important Rules of super Keyword in Java

Keep these rules in mind:

  1. super refers to the immediate parent class.

  2. super() calls the parent constructor.

  3. super() must be the first statement in a constructor.

  4. super.method() calls the parent implementation of an accessible instance method.

  5. super.variable accesses an accessible parent field.

  6. Private parent members cannot be accessed directly using super.

  7. super cannot be used in a static method.

  8. A constructor cannot directly use both this() and super().

  9. If no constructor call is written, Java attempts to insert super() automatically when the parent has an accessible no-argument constructor.

  10. In multi-level inheritance, super always refers to the immediate parent.


Java super Keyword: Quick Revision

If you are preparing for an exam, interview, or Java coding test, remember this:

Architecture Diagram
super
  │
  ├── super()              → Parent constructor
  │
  ├── super.method()       → Parent method
  │
  └── super.variable       → Parent variable

Example:

Main.java
Run Online
class Parent {
    String name = "Parent";
    Parent() {
        System.out.println("Parent constructor");
    } void show() {
        System.out.println("Parent method");
    }
}class Child extends Parent {
    String name = "Child";
    Child() {
        super();
    } void display() {
        System.out.println(super.name);
        super.show();
    }
}

This single example demonstrates all three major forms of super.

Runnable Code Example: The super Keyword in Java

Java 17+
Main.java
Run Online
class ParentService {
    void start() {
        System.out.println("Parent service starting");
    }
}class ChildService extends ParentService {
    @Override void start() {
        super.start();
        // Run parent initialization first
        System.out.println("Child service specific hooks configured");
    }
}public class SuperDemo {
    public static void main(String[] args) {
        new ChildService().start();
    }
}

Common Java Technical Interview Questions & Answers

Interview Prep
Q1

Can super be used to call methods from grandparents (e.g. super.super.method())?

No, Java prohibits super.super to enforce encapsulation of the immediate parent hierarchy.
Q2

What happens if super() is called after other statements in a constructor?

The compiler issues a compile error: 'call to super must be first statement in constructor'.

Key Takeaways, Best Practices & Clean Code Rules

Java Best Practice & Production Rules

Call super.overriddenMethod() when extending behavior in lifecycle hooks (e.g. init, destroy, start) to ensure parent state is properly maintained.