Interview Q&A · Java · 5 questions in this topic

this vs super — Java Interview Q&A

All Java topics

this refers to the current object; super reaches into the superclass. Both double as constructor calls — this(...) and super(...) — with strict first-statement rules. Part of Methods & Constructors · 294 questions in the Java bank.

What is the super keyword?

Answer

super is a reference to the superclass portion of the current object. It lets subclass code reach a hidden field or an overridden method (super.method(), super.field) and invoke a superclass constructor (super(...)). Like this(...), a super(...) call must be the first statement of a constructor.

Example

Example.javajava
class Vehicle { void start() { System.out.println("vehicle"); } }
class Car extends Vehicle {
    @Override void start() {
        super.start();                 // run the hidden superclass version
        System.out.println("car");
    }
}

What is the difference between this() and super()?

Answer

Both are constructor calls and both must be the first statement of the constructor that contains them. this(...) chains to another constructor of the same class; super(...) chains to a constructor of the direct superclass. Because only one statement can be first, a constructor uses one or the other — never both.

Key points

  1. 1this(...) → same-class constructor (constructor chaining).
  2. 2super(...) → superclass constructor; if omitted, the compiler inserts super().
  3. 3Used as plain references, this means "this object" and super means "the superclass view of this object".

Can a constructor call both this() and super()?

Answer

No. Either a constructor delegates to another constructor of the same class with this(...), or it calls a superclass constructor with super(...), and whichever it is must be the first statement. If neither is written, the compiler inserts a no-argument super() call, which fails to compile when the superclass has no accessible no-argument constructor. Chained constructors form a single chain that ends in exactly one super() call at the top.

Key points

  1. 1this() and super() are mutually exclusive in one constructor.
  2. 2Whichever is used must be the first statement.
  3. 3A missing call means an implicit no-argument super().
  4. 4The chain reaches exactly one superclass constructor.

Example

Example.javajava
class Point {
    Point() { this(0, 0); }          // delegates
    Point(int x, int y) { super(); }  // implicit anyway
}

Recommended resourcesAffiliate links · may earn us a commission

Classic DSA interview booksThe reference books interviewers themselves learned from — great next to the visualizers.See the books Structured coding coursesVideo courses that pair well with visual practice — pick one language and go deep.Browse courses Cloud hosting for side projectsShip the portfolio project that gets you hired — free credits for new accounts.Claim credits