9.4 super, this & Constructor Execution Order

Key Takeaways

  • Use super.member to access hidden superclass fields or call overridden superclass instance methods, but never inside a static context and never chained as super.super

  • An explicit this(...) or super(...) call must be the very first statement in a constructor, and a single constructor may contain at most one such call

  • A normal subclass constructor without an explicit this or super invocation begins with an implicit super().

  • If no accessible superclass constructor is applicable to super(), explicitly select a compatible one or use a this(...) chain that does.

  • Class initialization is separate from loading. During construction, each class’s instance initializers run once, after its superclass constructor completes and before its remaining constructor body.

Last updated: November 2026

super, this & Constructor Execution Order

When subclasses hide fields, override methods, or add overloaded constructors, Java relies on this and super to disambiguate members and chain initialization cleanly from java.lang.Object down to the concrete subclass.

super.member vs. this.member

Inside an instance method or constructor:

  • this.member accesses a member through the current instance and can disambiguate a field from a parameter. A method invocation through this can still dispatch to a subclass override.
  • super.member begins lookup in the superclass. A call such as super.bonus() invokes the selected superclass implementation without virtual dispatch to the current class.
class Employee {
    protected double base = 50000;
    public double bonus() { return 1000; }
}

class Manager extends Employee {
    private double base = 80000; // Hides Employee.base

    @Override
    public double bonus() {
        return super.bonus() + 2500; // Calls Employee.bonus() -> 3500
    }

    public void report(double base) {
        System.out.println(base);       // Local parameter
        System.out.println(this.base);  // Manager.base (80000)
        System.out.println(super.base); // Employee.base (50000)
    }
}

Hard Restrictions on super and this

  1. No static context: Neither this nor super can appear inside a static method, static initializer block, or static field initializer (non-static variable super cannot be referenced from a static context).
  2. No super.super chaining: Writing super.super.bonus() to skip Parent and reach Grandparent is a compile-time error. super is a keyword qualifier, not an object reference expression.
  3. Cannot reach private parent members: Private members are not inherited. A separate top-level subclass cannot use super.secret to bypass private access.

Constructor Chaining With this(...) and super(...)

For ordinary Java 8 subclasses, each constructor begins by delegating to another constructor in the same class or to a superclass constructor, either explicitly or with an implicit super(). Four strict rules govern this syntax:

RuleRequirementResult if Violated
1. First statement onlythis(...) or super(...) must be the very first statement in the constructorCompile-time error (call to super/this must be first statement)
2. At most one callA constructor cannot contain both this(...) and super(...), nor two this(...) callsCompile-time error
3. Implicit super()If neither this(...) nor super(...) is written, javac inserts super(); automaticallyInvokes an accessible superclass constructor applicable to zero arguments, which may be varargs
4. No cycles or method callsConstructors only; recursive this(...) cycles are forbiddenCompile-time error (recursive constructor invocation)

Look at how these rules interact in code:

class Device {
    Device(String serial) { }
}

class Sensor extends Device {
    private int rate;

    Sensor() {
        this("DEFAULT", 10); // Valid: chains to overloaded Sensor constructor
        // super("X");       // DOES NOT COMPILE: cannot have both this() and super()
    }

    Sensor(String serial, int rate) {
        // System.out.println(rate); // DOES NOT COMPILE if placed BEFORE super(serial)!
        super(serial);       // Must be the VERY FIRST statement
        this.rate = rate;
    }
}

Notice that Sensor() does not call super(...) directly—it delegates to Sensor(String, int) via this("DEFAULT", 10), and that constructor calls super(serial). Eventually, every this(...) chain must terminate at a constructor that invokes super(...).

Warning

The explicit constructor invocation cannot use the current object’s instance members. Arguments can use constructor parameters, static members, or another object’s accessible members.


The Missing No-Arg Parent Constructor Trap

The compiler synthesizes a default no-argument constructor only when a class declares zero constructors. A parent that declares only Parent(int) has no constructor applicable to super(). In the examples below, the subclass must explicitly select the available constructor:

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

// Example A: Compiler inserts default constructor Child() { super(); }
// class ChildA extends Parent { } // DOES NOT COMPILE: Parent() does not exist!

// Example B: Explicit constructor without explicit super(...) or this(...)
// class ChildB extends Parent {
//     ChildB() { } // Implicit super() does not compile here.
// }

// Example C: Fixed by calling super(int)
class ChildC extends Parent {
    ChildC() {
        super(100); // Compiles cleanly!
    }
}

This trap is one of the highest-frequency questions in inheritance sections: even an empty class ChildA extends Parent {} fails to compile if Parent defines Parent(int x) and no Parent().


Tracing Initialization & Constructor Order Across Levels

For this ordinary class hierarchy, assume the classes have not yet been initialized and that each initializer and constructor completes normally:

  1. Class initialization: On an active use that triggers initialization, ordinary static field initializers and static blocks run from Grandparent to Parent to Child, in textual order within each class. Loading alone does not trigger initialization, and constant variables have special rules. When relevant, class initialization also initializes its superinterfaces that declare default methods. This example has no such interfaces.
  2. Constructor chaining (bottom-up): new Child() invokes Child() -> super() (Parent()) -> super() (Grandparent()) -> super() (Object()).
  3. Instance initialization & constructor bodies (top-down):
    • Object() completes.
    • Grandparent instance fields & { ... } initializer blocks run in textual order -> Grandparent constructor body completes.
    • Parent instance fields & { ... } initializer blocks run in textual order -> Parent constructor body completes.
    • Child instance fields & { ... } initializer blocks run in textual order -> Child constructor body completes.

Trace the exact output of this complete Java SE 8 program:

class Grandparent {
    static { System.out.print("1 "); }
    { System.out.print("4 "); }
    Grandparent() { System.out.print("5 "); }
}

class Parent extends Grandparent {
    static { System.out.print("2 "); }
    { System.out.print("6 "); }
    Parent(String msg) {
        // Implicit super() runs Grandparent instance init + constructor first
        System.out.print("7:" + msg + " ");
    }
}

public class Child extends Parent {
    static { System.out.print("3 "); }
    { System.out.print("8 "); }
    Child() {
        this(9);
        System.out.print("10 ");
    }
    Child(int n) {
        super("OK");
        System.out.print(n + " ");
    }
    public static void main(String[] args) {
        new Child();
    }
}

Exact output: 1 2 3 4 5 6 7:OK 8 9 10

Let us verify every token:

  • Class initialization before the launcher invokes main: Grandparent (1), Parent (2), Child (3).
  • new Child() chains: Child() -> this(9) -> super("OK") (Parent("OK")) -> implicit super() (Grandparent()) -> Object().
  • Grandparent finishes: instance block (4), constructor body (5).
  • Parent finishes: instance block (6), constructor body (7:OK).
  • Child finishes: instance block (8 runs once after super("OK") returns, NOT once per this(...) call!), Child(int) body (9), then Child() body (10).

Important

Instance initializer blocks and instance field initializers run immediately after super(...) completes—not after this(...)! Even when Child() chains through this(9), Child's instance block (8) runs exactly once before Child(int) executes its body.

Test Your Knowledge

Given:

class Alpha {
    Alpha(String s) { System.out.print(s); }
}
class Beta extends Alpha {
    Beta() { System.out.print("B"); }
    public static void main(String[] args) { new Beta(); }
}

What is the result?

A

Prints B

B

Prints nullB

C

Throws RuntimeException because Alpha was not initialized

D

Fails to compile because Alpha has no no-argument constructor

Test Your Knowledge

Which constructor declaration inside class Sub extends Super compiles if Super() and Super(int) are accessible and neither declares checked exceptions?

A

Sub() { System.out.println("start"); super(5); }

B

Sub() { this(5); } Sub(int x) { super(x); }

C

Sub() { super(); this(5); } Sub(int x) { }

D

Sub() { this(5); } Sub(int x) { this(); }

Test Your Knowledge

What does the following program print?

class One {
    static { System.out.print("A"); }
    { System.out.print("B"); }
    One() { System.out.print("C"); }
}
class Two extends One {
    static { System.out.print("D"); }
    { System.out.print("E"); }
    Two() { this(1); System.out.print("F"); }
    Two(int x) { System.out.print("G"); }
    public static void main(String[] args) { new Two(); }
}
A

ABCDEFG

B

ADBCGEF

C

ADBCEGF

D

BCADEGF

Sections you finish are checked off in the contents.