Java super Keyword Explained: Constructors, Methods, and Fields (With Examples)

目次

1. Relationship Between Inheritance and super

To understand Java’s super keyword, you should first understand inheritance.
super is not something you memorize in isolation—its meaning becomes clear once you see how a child class and a parent class work together.

In this section, you’ll learn what inheritance is and why super exists in the first place, using beginner-friendly explanations and simple code examples.

1.1 What Is Inheritance in Java? (extends Basics)

In Java, inheritance allows you to create a new class based on an existing class.

  • Parent class (superclass): the base class
  • Child class (subclass): the class that inherits from the parent class

When a child class extends a parent class, it can reuse the parent’s fields and methods without rewriting them.

Basic inheritance syntax (extends)

class Parent {
    void hello() {
        System.out.println("Hello from Parent");
    }
}

class Child extends Parent {
}

Here, Child inherits the hello() method from Parent.

public class Main {
    public static void main(String[] args) {
        Child child = new Child();
        child.hello(); // calling a method inherited from Parent
    }
}

Output:

Hello from Parent

So even though Child does not define hello(), it can still call it because it inherited it.

1.2 Why Do We Need super?

At this point, you might think:

“If the child already inherits everything from the parent, why do we need super at all?”

In many cases, you don’t need to write super explicitly.
However, super becomes necessary when you want to clearly access the parent version of something.

Common situations include:

  • The child class overrides a method, but you still want to call the parent version
  • The child class and parent class have fields with the same name
  • You need to call a specific parent constructor using arguments

In short:

super is used when you want to explicitly refer to the parent class side.

1.3 Overriding and super (Keeping the Parent Behavior)

One of the most common reasons to use super is method overriding.

Overriding means the child class provides its own version of a method that already exists in the parent class.

Example: overriding a method

class Parent {
    void greet() {
        System.out.println("Parent: Hello!");
    }
}

class Child extends Parent {
    @Override
    void greet() {
        System.out.println("Child: Hi!");
    }
}

Now if you call greet() on a Child object:

public class Main {
    public static void main(String[] args) {
        Child child = new Child();
        child.greet();
    }
}

Output:

Child: Hi!

The child version runs, because overriding gives the child class priority.

Calling the parent version with super.greet()

Sometimes you don’t want to completely replace the parent behavior—you just want to add extra logic.

That’s where super.method() is useful:

class Parent {
    void greet() {
        System.out.println("Parent: Hello!");
    }
}

class Child extends Parent {
    @Override
    void greet() {
        super.greet(); // call parent version
        System.out.println("Child: Hi!");
    }
}

Output:

Parent: Hello!
Child: Hi!

This is a very practical pattern:

  • Parent class handles common behavior
  • Child class adds custom behavior

1.4 When Parent and Child Have the Same Field Name

Another situation where super matters is when a parent and child class have fields with the same name.

Example:

class Parent {
    int value = 100;
}

class Child extends Parent {
    int value = 200;

    void printValue() {
        System.out.println(value);
    }
}

Here, value refers to the child class field, so the output will be:

200

If you want to access the parent field, use super.value:

class Child extends Parent {
    int value = 200;

    void printValue() {
        System.out.println(value);       // child value
        System.out.println(super.value); // parent value
    }
}

Output:

200
100

Key takeaway:

  • value → child class field
  • super.value → parent class field

1.5 What super Really Means (Simple Definition)

Now you can summarize super like this:

super is a keyword that lets you explicitly access the parent class version of fields, methods, and constructors.

If you remember just one line, remember this:

super means “use the parent class version.”

In the next section, you’ll learn the 3 most important ways to use super, with clear examples for each.

2. How to Use super (3 Core Patterns)

Now that you understand what super means, let’s focus on how it’s actually used in Java.

In real-world code, super appears in three main patterns:

  1. Calling a parent constructor (super() / super(args...))
  2. Calling a parent method (super.method())
  3. Accessing a parent field (super.field)

Once you learn these three, super becomes very easy to recognize and use correctly.

2.1 Calling a Parent Constructor (super() / super(args...))

2.1.1 Quick refresher: What is a constructor?

A constructor is a special method that runs when you create an object.

class Person {
    Person() {
        System.out.println("Person constructor");
    }
}

Constructors are used for initialization, such as setting up fields.

2.1.2 In inheritance, the parent constructor runs first

In Java inheritance, creating a child object always starts by initializing the parent part first.

That means:

Parent constructor → Child constructor

Example:

class Parent {
    Parent() {
        System.out.println("Parent constructor");
    }
}

class Child extends Parent {
    Child() {
        System.out.println("Child constructor");
    }
}

public class Main {
    public static void main(String[] args) {
        new Child();
    }
}

Output:

Parent constructor
Child constructor

Even though we didn’t write super(), the parent constructor still ran.

2.1.3 super() is inserted automatically (when possible)

If the parent class has a no-argument constructor, Java automatically inserts this line at the top of the child constructor:

super();

So these two constructors are effectively the same:

Child() {
    System.out.println("Child constructor");
}
Child() {
    super(); // implicitly inserted by the compiler
    System.out.println("Child constructor");
}

2.1.4 When the parent has only a parameterized constructor

This is one of the most common beginner mistakes.

If the parent class does not have a no-argument constructor, Java cannot insert super() automatically.

Example (this will cause a compile error):

class Parent {
    Parent(int x) {
        System.out.println("Parent: " + x);
    }
}

class Child extends Parent {
    Child() {
        System.out.println("Child created");
    }
}

Why it fails:

  • The compiler tries to insert super();
  • But Parent() does not exist

✅ Fix: explicitly call the correct parent constructor

class Child extends Parent {
    Child() {
        super(10);
        System.out.println("Child created");
    }
}

Output:

Parent: 10
Child created

2.1.5 super(...) must be the first line in the constructor

Java requires super(...) to be the first statement in a constructor.

❌ Wrong:

Child() {
    System.out.println("Something first");
    super(10); // compile error
}

✅ Correct:

Child() {
    super(10);
    System.out.println("Child logic");
}

Reason:

  • The parent must be initialized before the child can safely run its own logic.

2.2 Calling a Parent Method (super.method())

Another very common use case is calling the parent method after overriding.

2.2.1 Basic example

class Parent {
    void show() {
        System.out.println("Parent show()");
    }
}

class Child extends Parent {
    @Override
    void show() {
        System.out.println("Child show()");
    }

    void test() {
        super.show(); // parent version
        show();       // child version
    }
}

public class Main {
    public static void main(String[] args) {
        new Child().test();
    }
}

Output:

Parent show()
Child show()

2.2.2 When is this useful?

super.method() is useful when:

  • The parent method contains common logic
  • The child method needs to extend behavior instead of replacing it
  • You want to avoid copy-pasting parent logic into the child

Example:

class Parent {
    void process() {
        System.out.println("Common processing");
    }
}

class Child extends Parent {
    @Override
    void process() {
        super.process();
        System.out.println("Child-specific processing");
    }
}

This pattern keeps your code clean and maintainable.

2.3 Accessing a Parent Field (super.field)

Fields work similarly. If both parent and child have a field with the same name, the child field hides the parent field.

Example:

class Parent {
    int value = 100;
}

class Child extends Parent {
    int value = 200;

    void print() {
        System.out.println(value);       // child field
        System.out.println(super.value); // parent field
    }
}

public class Main {
    public static void main(String[] args) {
        new Child().print();
    }
}

Output:

200
100

2.3.1 Should you do this in real projects?

Usually, having the same field name in parent and child is not a great idea because it can confuse readers.

However, it can happen when:

  • You’re maintaining legacy code
  • You’re forced to match an existing parent class design
  • You need to clearly differentiate parent vs child values

In those cases, super.field is the correct tool.

2.4 Summary of the 3 patterns

You can remember super like this:

  • super() / super(args...) → call parent constructor
  • super.method() → call parent method
  • super.field → access parent field

In the next section, we’ll go deeper with practical code examples so you can clearly see how these patterns behave when executed.

3. Practical Examples to Master super

At this point, you already know the three core ways to use super.
Now let’s make that knowledge stick by running through practical examples.

This section focuses on:

  • Execution order
  • What gets called and why
  • How super changes behavior in real code

3.1 Example 1: Constructor call order (Parent → Child)

The most important rule to remember:

When creating a child object, Java always initializes the parent part first.

class Parent {
    Parent() {
        System.out.println("Parent constructor");
    }
}

class Child extends Parent {
    Child() {
        super(); // optional here, but allowed
        System.out.println("Child constructor");
    }
}

public class Main {
    public static void main(String[] args) {
        new Child();
    }
}

Output:

Parent constructor
Child constructor

Key point:
Even if you remove super(), the result is the same (as long as the parent has a no-arg constructor).

3.2 Example 2: Parent has only a parameterized constructor

If the parent class does not have a no-argument constructor, the child must explicitly call the correct one.

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

class Child extends Parent {
    Child() {
        super("Taro");
        System.out.println("Child created");
    }
}

public class Main {
    public static void main(String[] args) {
        new Child();
    }
}

Output:

Parent: Taro
Child created

Key point:
If you forget super("Taro"), Java tries to insert super() automatically and fails.

3.3 Example 3: Calling a parent method after overriding (super.method())

This is one of the most useful patterns in real projects.

class Parent {
    void greet() {
        System.out.println("Hello from Parent");
    }
}

class Child extends Parent {
    @Override
    void greet() {
        super.greet(); // call parent behavior
        System.out.println("Hello from Child");
    }
}

public class Main {
    public static void main(String[] args) {
        new Child().greet();
    }
}

Output:

Hello from Parent
Hello from Child

Key point:
You can extend parent behavior without rewriting it.

3.4 Example 4: Accessing a hidden parent field (super.field)

If parent and child both define a field with the same name, the child version hides the parent version.

class Parent {
    int value = 100;
}

class Child extends Parent {
    int value = 200;

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

public class Main {
    public static void main(String[] args) {
        new Child().printValues();
    }
}

Output:

Child value: 200
Parent value: 100

Key point:

  • value refers to the child’s field
  • super.value refers to the parent’s field

3.5 Example 5: Calling both parent and child versions clearly

This is a great example to remove confusion.

class Parent {
    void show() {
        System.out.println("Parent show()");
    }
}

class Child extends Parent {
    @Override
    void show() {
        System.out.println("Child show()");
    }

    void test() {
        super.show(); // parent version
        this.show();  // child version (same as just calling show())
    }
}

public class Main {
    public static void main(String[] args) {
        new Child().test();
    }
}

Output:

Parent show()
Child show()

Key point:

  • super.show() = parent
  • this.show() = child

3.6 A realistic example: shared logic in the parent class

In real applications, parent classes often contain common logic such as logging, validation, or setup steps.

class BaseService {
    void execute() {
        System.out.println("[LOG] Start execution");
    }
}

class UserService extends BaseService {
    @Override
    void execute() {
        super.execute(); // reuse shared behavior
        System.out.println("UserService logic running...");
    }
}

public class Main {
    public static void main(String[] args) {
        new UserService().execute();
    }
}

Output:

[LOG] Start execution
UserService logic running...

Why this is useful:

  • You avoid duplicating common behavior
  • The child focuses only on what’s unique
  • Your code becomes easier to maintain

3.7 Section summary

From these examples, you should remember:

  • Parent constructors run before child constructors
  • super(args...) is required if the parent has no no-arg constructor
  • super.method() is perfect for reusing and extending behavior
  • super.field helps when parent and child fields share the same name

Next, we’ll clarify one of the most confusing topics for beginners:

What’s the difference between this and super?

4. Difference Between this and super

When learning Java’s super, you will almost always see this at the same time.
Both are reference keywords, so it’s easy for beginners to mix them up.

In this section, you’ll learn:

  • What this means
  • What super means
  • How to use them correctly with fields, methods, and constructors

4.1 this refers to the current object (the child instance)

this means:

“the current object instance”

It is most commonly used when a field name and a constructor parameter name are the same.

class User {
    String name;

    User(String name) {
        this.name = name; // field = parameter
    }
}

Here:

  • name (right side) is the constructor parameter
  • this.name (left side) is the instance field

So this helps you avoid confusion.

4.2 super refers to the parent class side

super refers to the parent class (superclass) part of the current object.

It means:

“use the parent class version”

You mainly use it when you want to access parent members that are hidden or overridden.

4.3 The simplest way to remember the difference

A beginner-friendly way to memorize:

  • thisthe child class side
  • superthe parent class side

They are not two different objects.
They are two different “views” of the same object.

4.4 Using this and super with fields

If both parent and child define a field with the same name, you can clearly choose which one you want.

class Parent {
    int value = 100;
}

class Child extends Parent {
    int value = 200;

    void print() {
        System.out.println(this.value);  // child field
        System.out.println(super.value); // parent field
    }
}

public class Main {
    public static void main(String[] args) {
        new Child().print();
    }
}

Output:

200
100

Key point:

  • this.value = child field
  • super.value = parent field

Also, in Java, this is often optional:

System.out.println(value);

is the same as:

System.out.println(this.value);

4.5 Using this and super with methods

Methods are the most common area where this vs super matters—especially with overriding.

class Parent {
    void show() {
        System.out.println("Parent show()");
    }
}

class Child extends Parent {
    @Override
    void show() {
        System.out.println("Child show()");
    }

    void test() {
        this.show();   // child method (same as show())
        super.show();  // parent method
    }
}

public class Main {
    public static void main(String[] args) {
        new Child().test();
    }
}

Output:

Child show()
Parent show()

Key point:

  • this.show() → child version
  • super.show() → parent version

4.6 Constructors: this() vs super()

This is one of the most confusing parts for beginners, but it’s very important.

  • this() calls another constructor in the same class
  • super() calls a constructor in the parent class

4.6.1 Example of this() (constructor chaining inside the same class)

class User {
    String name;
    int age;

    User() {
        this("NoName", 0); // call another constructor
    }

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

This is useful because it avoids repeating initialization logic.

4.6.2 Example of super() (calling the parent constructor)

class Parent {
    Parent() {
        System.out.println("Parent constructor");
    }
}

class Child extends Parent {
    Child() {
        super(); // initialize parent
        System.out.println("Child constructor");
    }
}

Output:

Parent constructor
Child constructor

4.7 You cannot use this() and super() together

Many beginners try something like this:

Child() {
    this(1);
    super(); // error
}

This is not allowed.

Reason:

  • Both this() and super() must be the first line in the constructor
  • Only one of them can be first

So you must choose one.

4.8 Important reminder: super does not create a new object

super does not create a separate parent object.

Instead:

  • this = current object viewed as a child
  • super = same object viewed as a parent

This is why super is best thought of as a reference keyword, not an object creator.

4.9 Section summary

  • this refers to the current object (child side)
  • super refers to the parent class side
  • this() calls another constructor in the same class
  • super() calls a constructor in the parent class
  • this() and super() cannot be used together

Next, we’ll cover common mistakes and error patterns so you can avoid the most frequent beginner traps.

5. Common Mistakes and Pitfalls (How to Avoid Errors)

Java’s super keyword is powerful, but it’s also easy to misuse—especially when you’re still learning inheritance and constructors.

In this section, you’ll learn the most common mistakes beginners make and how to fix them quickly.

5.1 Writing super(...) in the wrong place (constructor rule)

One of the most important rules:

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

❌ Wrong (compile error):

class Parent {
    Parent(int x) {}
}

class Child extends Parent {
    Child() {
        System.out.println("Do something first");
        super(10); // ERROR: must be first line
    }
}

✅ Correct:

class Child extends Parent {
    Child() {
        super(10);
        System.out.println("Child logic");
    }
}

Why?
Because the parent part of the object must be initialized before the child logic runs.

5.2 Forgetting super(args...) when the parent has no no-arg constructor

If the parent class has only a parameterized constructor, Java cannot automatically insert super().

❌ Wrong:

class Parent {
    Parent(String name) {}
}

class Child extends Parent {
    Child() {
        // compiler tries to insert super() here -> ERROR
    }
}

✅ Correct:

class Child extends Parent {
    Child() {
        super("Taro");
    }
}

This is a very common compile error for beginners, so always check the parent constructors.

5.3 Trying to use both this() and super() in the same constructor

Beginners often think:

“I want to call another constructor AND the parent constructor.”

But Java does not allow this.

❌ Wrong:

class Parent {
    Parent() {}
}

class Child extends Parent {
    Child() {
        this(1);
        super(); // ERROR
    }

    Child(int x) {}
}

Reason:

  • this() and super() must both be the first line
  • Only one can be first

So you must design your constructors so that only one is used directly.

5.4 Trying to use super inside a static method

super is tied to the current object instance, so it doesn’t work in static methods.

❌ Wrong (conceptually):

class Parent {
    void hello() {}
}

class Child extends Parent {
    static void test() {
        super.hello(); // ERROR
    }
}

Key point:

  • Static methods belong to the class, not an instance
  • super refers to the parent part of an instance

So Java prevents this.

5.5 Misunderstanding super as “creating a parent object”

Some beginners assume:

“Using super creates a separate parent object.”

That’s not true.

super does not create a new object.
It simply accesses the parent class side of the same object.

Think of it like this:

  • this = same object, child view
  • super = same object, parent view

5.6 Using super.field too often (field hiding is usually a bad idea)

Yes, super.field exists—but in most real projects, you should avoid creating parent/child fields with the same name.

Example (confusing design):

class Parent {
    int value = 100;
}

class Child extends Parent {
    int value = 200; // hides parent field
}

Even though super.value works, this design makes code harder to read and maintain.

Better practice:

  • Use different field names
  • Keep fields private and expose them with methods (getters)
  • Avoid hiding fields unless absolutely necessary

5.7 “If I call super.method(), only parent logic runs” (not always)

This is slightly more advanced, but useful to know.

When you call super.method(), you definitely call the parent method.
However, inside that parent method, if it calls another method that the child overrides, the child version may run.

Example:

class Parent {
    void a() {
        b(); // calls b()
    }

    void b() {
        System.out.println("Parent b()");
    }
}

class Child extends Parent {
    @Override
    void b() {
        System.out.println("Child b()");
    }
}

public class Main {
    public static void main(String[] args) {
        Child c = new Child();
        c.a();
    }
}

Output:

Child b()

Even though a() is in the parent, it calls b(), and b() is overridden in the child.

Beginner takeaway:
super.method() calls the parent version of that method, but method calls inside it may still use overriding rules.

5.8 Quick checklist (to avoid beginner errors)

Before you use super, check these:

  • Is super(...) the first line in the constructor?
  • Does the parent class have a no-arg constructor?
  • Are you trying to use both this() and super()?
  • Are you using super inside a static method?
  • Are you hiding fields with the same name unnecessarily?

6. Conclusion (Key Takeaways)

In this article, you learned what Java’s super keyword is, why it exists, and how to use it correctly in real code.

Let’s wrap everything up with the most important points you should remember.

6.1 What does super mean in Java?

super is a keyword that lets you explicitly access the parent class (superclass) part of an object.

It is mainly used in inheritance (extends) when you want to refer to the parent version of:

  • constructors
  • methods
  • fields

In simple terms:

super means “use the parent class version.”

6.2 The 3 most important ways to use super

You can memorize super in these three patterns:

1) Call the parent constructor

  • super()
  • super(args...)

This is used when you need to initialize the parent class properly, especially if the parent requires arguments.

2) Call the parent method

  • super.method()

This is useful when you override a method but still want to reuse the parent behavior.

3) Access the parent field

  • super.field

This is used when both parent and child have a field with the same name and you want to clearly refer to the parent one.

6.3 this vs super (the easiest way to understand it)

Many beginners confuse these two keywords, but the difference is simple:

  • this → the current object (child-side view)
  • super → the parent-side view of the same object

They do not represent two different objects.

6.4 Most errors happen around constructors

If you want to avoid the most common mistakes, remember these rules:

  • super(...) must be the first line inside a constructor
  • If the parent has no no-arg constructor, you must write super(args...)
  • You cannot use this() and super() together in the same constructor
  • super does not work in static methods

6.5 Final takeaway: super helps you reuse and extend parent logic safely

The real power of super is that it allows you to:

  • keep shared logic in the parent class
  • extend behavior in the child class
  • avoid copy-pasting code
  • make inheritance cleaner and easier to maintain

If you remember one line from this entire article, remember this:

super is the keyword you use when you want the parent class version.

7. FAQ (Frequently Asked Questions)

Here are the most common questions beginners ask when learning Java’s super keyword.
If you’re still feeling unsure about certain parts, this section should clear things up quickly.

7.1 When should I use super in Java?

You typically use super in these situations:

  • When you want to call a parent constructor (super() / super(args...))
  • When you override a method but still want to call the parent method (super.method())
  • When the parent and child have the same field name and you want the parent field (super.field)

For beginners, the most common and useful case is:

overriding a method and calling the parent logic using super.method().

7.2 What happens if I don’t write super()?

If the parent class has a no-argument constructor, Java automatically inserts:

super();

at the top of the child constructor.

So in many cases, you don’t need to write it manually.

However, if the parent class does not have a no-arg constructor, the code will fail unless you explicitly call the correct one with arguments.

7.3 What’s the difference between super() and this()?

They call different constructors:

  • super() → calls a constructor in the parent class
  • this() → calls a constructor in the same class

Example idea:

  • Use this() to reduce duplicated constructor code
  • Use super() to properly initialize the parent part of the object

7.4 Can I use both this() and super() in the same constructor?

No, you cannot.

Reason:

  • Both this() and super() must be the first statement in the constructor
  • Only one statement can be first

So Java forces you to choose one.

7.5 Can I use super inside a static method?

No (in general).

super is related to the current object instance, but static methods belong to the class itself and do not have an instance reference.

That’s why using super in static methods results in a compile error.

7.6 Does super create a new parent object?

No.

super does not create any new object.

It simply accesses the parent class view of the same object.

A helpful way to think about it:

  • this = same object viewed as a child
  • super = same object viewed as a parent

7.7 If I call super.method(), does it always run only the parent logic?

super.method() always calls the parent version of that method.

However, if the parent method internally calls another method that the child overrides, then the child version may run due to Java’s overriding rules.

Beginner-level takeaway:

super.method() calls the parent version, but method calls inside it may still be affected by overriding.

7.8 Should I use super.field often?

Usually, no.

If you frequently need super.field, it may mean your design is confusing because the parent and child share the same field name.

In real projects, it’s better to avoid field hiding unless you have a strong reason (such as legacy code or external constraints).

7.9 Can super be used with interfaces?

In normal inheritance (extends), super refers to the parent class.

However, Java also allows a special syntax to call an interface default method:

InterfaceName.super.method();

This is more advanced, so if you’re a beginner, focus first on:

  • class inheritance
  • super() / super.method() / super.field

7.10 What’s the fastest way to master super?

A simple learning path:

  1. Write a basic parent/child class and confirm constructor order
  2. Override a method and call super.method()
  3. Compare this vs super with fields and methods
  4. Practice fixing constructor-related errors

The best practice is to write small examples and run them.