super Keyword in Java: Uses with Examples

The super keyword in Java is a reference variable used inside a subclass to access the immediate parent class constructor, methods, and fields. It has three uses: super() calls the parent constructor, super.method() invokes an overridden parent method, and super.variable accesses a hidden parent field. It cannot be used in static methods.

  • super() calls the parent class constructor and must be the first statement in a subclass constructor.
  • super.method() lets a subclass call a parent method that it has overridden.
  • super.variable accesses a parent class field when the child class has a field with the same name.
  • You cannot use super inside a static method because static context has no object reference.
  • Java automatically inserts a no-argument super() call if you don’t write one, but only if the parent has a default constructor.

What the super Keyword in Java Refers To

Java is built on object-oriented programming, and inheritance is one of its most-used features. According to the Oracle Java Documentation, the super keyword is a special reference that always points to the direct parent class, never to a grandparent or any further ancestor. That single-level scope is intentional and keeps the inheritance chain predictable.

When you define a class like class Dog extends Animal, the Dog object contains everything from Animal plus its own additions. The super keyword in Java is the handle you use to reach into the Animal part of that object. Without it, you’d have no clean way to separate a parent’s field or method from a child’s version of the same thing.

Java has consistently ranked in the top three languages on the TIOBE Index for over two decades, making inheritance-related questions a fixture in nearly every Java technical interview. According to the JetBrains State of Developer Ecosystem 2023, Java remains the primary language for 48% of backend developers worldwide, with OOP concepts like the super keyword appearing in daily production code. In India, NASSCOM estimates over 5 million active Java developers, and BTech and MCA placement rounds at institutions affiliated with AICTE consistently test super keyword usage in written and viva rounds. You can see the broader career picture in our guide on jobs and salary after MCA.

The Three Uses of super Keyword in Java at a Glance

Use Syntax What It Does
Call parent constructor super() or super(args) Invokes the parent class constructor from the child constructor
Call parent method super.methodName() Calls the parent version of an overridden method
Access parent variable super.variableName Reads a parent field hidden by a same-name child field

Calling the Parent Constructor with super() in Java

The most common use of the super keyword in Java is invoking the parent class constructor. You write super() or super(arguments) as the very first line inside your child constructor. If you put it anywhere else, the Java compiler throws a compile-time error immediately.

Here’s a realistic example. Imagine you’re building a university management system, the kind of project common in BSc CS and BCA final-year labs at Indian universities:


class Person {
    String name;
    int age;

    Person(String name, int age) {
        this.name = name;
        this.age = age;
    }
}

class Student extends Person {
    String rollNumber;

    Student(String name, int age, String rollNumber) {
        super(name, age);          // calls Person constructor
        this.rollNumber = rollNumber;
    }

    void display() {
        System.out.println(name + " | Age: " + age + " | Roll: " + rollNumber);
    }
}

Without super(name, age), the Student constructor would have to manually assign name and age itself. That’s duplicated code and a maintenance headache. Using super() keeps the parent’s initialisation logic in one place, which is exactly what constructor chaining in Java is meant to achieve.

What Happens If You Skip super() in a Java Constructor

If you don’t write any super() call, Java automatically inserts super() with no arguments. That’s fine when the parent class has a no-argument constructor. It becomes a compile-time error the moment the parent only has a parameterised constructor, because Java can’t guess what arguments to pass.

This is one of the most common beginner mistakes in Java. The error message reads something like “constructor Person in class Person cannot be applied to given types”, which confuses students who didn’t write any constructor call at all. Knowing this saves you debugging time. For a broader look at Java runtime problems, check our article on Java exceptions and common runtime errors.

Calling Parent Methods and Variables Using the super Keyword

The second and third uses of the super keyword in Java come into play when method overriding creates ambiguity. When a child class defines a method with the same name and signature as a parent method, the child version takes over completely, unless you explicitly call super.methodName().

super.method() in Action

Consider a payment processing app where a base class handles standard logging and a child class adds extra validation:


class Payment {
    void process() {
        System.out.println("Processing standard payment...");
    }
}

class UPIPayment extends Payment {
    @Override
    void process() {
        super.process();           // runs parent logic first
        System.out.println("Verifying UPI ID...");
    }
}

Calling super.process() means you don’t rewrite the parent’s logic. You extend it. This pattern is extremely common in Android development and enterprise Java frameworks like Spring, where base classes handle boilerplate and subclasses add specifics. Indian fintech companies building UPI-based apps rely on exactly this kind of OOP inheritance hierarchy in their Java backends.

Accessing Parent Variables with super.variable

When a child class declares a field with the same name as a parent field, the child field hides the parent field. You use super.variableName to reach the parent version:


class Vehicle {
    String type = "Generic Vehicle";
}

class Car extends Vehicle {
    String type = "Car";

    void showTypes() {
        System.out.println("Child type: " + type);
        System.out.println("Parent type: " + super.type);
    }
}

Variable hiding is less common than method overriding in Java, but it trips up students in exams and interviews. The Stack Overflow Developer Survey 2024 found Java among the top five most-used languages by professional developers globally, which means these fundamentals come up constantly in real codebases, not just classrooms.

If you’re just starting out with compiled languages, our guide on how to write, compile and run a C program gives useful context on how compilers handle inheritance-related constructs across languages. You’ll also want to know the software development tools to learn first before you start building real Java projects.

super vs this in Java: Key Differences

Both super and this are reference variables in Java, and confusing them is one of the most reliable ways to introduce subtle bugs. They look similar in syntax but point to completely different objects.

super vs this: Side-by-Side Comparison

Feature super this
Refers to Immediate parent class object Current class object
Constructor call super() calls parent constructor this() calls another constructor in same class
Method call super.method() calls overridden parent method this.method() calls current class method
Variable access super.var accesses hidden parent field this.var resolves ambiguity with local variable
Works in static? No No
First statement rule super() must be first in constructor this() must be first in constructor

One rule that catches people out: you can’t use both super() and this() in the same constructor. Both must be the first statement, so only one can win. Try to use both and the compiler refuses to compile.

A practical tip from real code reviews: use this to resolve local variable conflicts in setters, use super to extend parent behaviour in overridden methods. Keep those two scenarios distinct in your mind and you’ll almost never misuse either keyword. Understanding these distinctions matters whether you’re aiming to be a full stack developer or a software developer, because both roles write OOP code daily.

Students in BSc Computer Science subjects and scope programmes typically cover this in their second-year Java or OOP papers, and it almost always appears in university practicals and viva questions under AICTE-affiliated colleges across India.

super Keyword in Java: Interview Questions to Know

Java interviews at Indian product companies and service firms like TCS, Infosys, and Wipro regularly test the use of super keyword in Java at both fresher and experienced levels. Common questions include: what happens when super() is missing, can super be used in an interface, and what is the difference between super and this in constructor chaining. Knowing the answers cold gives you a clear edge in campus placements.

Wrapping up: the super keyword in Java solves a specific, recurring problem in inheritance: how does a child class reach into its parent without rewriting or breaking the parent’s logic? The answer is always super. Master its three uses and you’ll write cleaner, more maintainable Java code from day one.

  1. Write a two-class Java program this week that uses all three forms of super: super(), super.method(), and super.variable. Compile and run it yourself.
  2. Review the Oracle Java tutorial on using the super keyword to see the official specification and edge cases.
  3. If you’re building toward a career in cybersecurity, AI, or ethical hacking, explore 3.0 University’s online certification courses. Strong Java fundamentals feed directly into secure coding, Android security testing, and AI application development. The CEH v13 AI online course is a practical next step once your programming foundation is solid.

Frequently Asked Questions

What is super keyword in Java?

The super keyword in Java is a reference variable used inside a subclass to access the immediate parent class’s constructor, methods, and fields. It is part of Java’s inheritance model and lets child classes build on parent functionality without duplicating code. It cannot be used in a static context.

What is the use of super keyword in Java?

The super keyword in Java has three main uses: calling the parent constructor with super(), invoking an overridden parent method with super.methodName(), and accessing a parent field hidden by a same-name child field with super.variableName. Each use helps manage the relationship between a parent and child class cleanly in OOP inheritance.

Can super be used in static methods in Java?

No. Static methods belong to the class itself, not to any object instance. The super keyword requires an object context because it references the parent part of a specific object. Using super inside a static method causes a compile-time error in Java.

What is super() in a Java constructor?

super() is a constructor call that invokes the parent class’s constructor from inside the child class’s constructor. It must be the very first statement in the child constructor. If you skip it and the parent has no default constructor, Java throws a compile-time error. This is called constructor chaining in Java.

What is the difference between super and this in Java?

The keyword this refers to the current class object, while super refers to the parent class object. You use this() to call another constructor in the same class and super() to call the parent constructor. Both must appear as the first statement in a constructor, so you can never use them together in the same constructor.

Can you use super keyword in an interface in Java?

No. Interfaces in Java do not have constructors and do not support the super keyword in the traditional sense. The super keyword applies only to class inheritance where a subclass extends a parent class. Default methods in interfaces use a different syntax for calling interface methods.

Last updated: June 2025. Reviewed by the 3University editorial team.

We create, review, and maintain educational content covering Cybersecurity, Ethical Hacking, Artificial Intelligence, Blockchain, Web3, and emerging technologies.

Read More Articles