Kit Library / Computer Science / Object-Oriented Programming

⚡ Topic Learning Kit

Java this and super Keywords

English 17 leveled MCQs 20 flashcards 9 games Free

Shared by a Veda learner · Generated with Veda AI

Veda Bites

The whole idea, one bite at a time

Veda Bites are swipeable micro-lessons — each one teaches exactly one idea. The bites below come from this kit — swipe through them in the app.

💡 Key Idea

this vs super: Two References, Two Targets

One points inward, one points upward.

`this` refers to the current object; `super` refers to the immediate parent class of the current object.

↳ Use `this` to talk about yourself; use `super` to talk to your parent.

📖 Definition

What Exactly Is 'this'?

The object's self-portrait.

↳ `this` is how an object refers to itself inside its own methods and constructors.

📖 Definition

What Exactly Is 'super'?

The parent's doorway.

↳ `super` lets a subclass access members and constructors of its direct parent.

💡 Use Case

Resolving Variable Shadowing with 'this'

Same name, different scope.

When a constructor parameter has the same name as an instance field, `this.field` disambiguates.

↳ `this.field` always refers to the instance variable, not the local parameter.

💡 Use Case

Accessing Hidden Parent Fields with 'super'

When the child hides the parent's field.

If a subclass declares a field with the same name as a parent field, `super.field` accesses the parent's version.

↳ `super.x` bypasses the child's shadowing field and reads the parent's field.

💡 Use Case

Calling Overridden Methods with 'super'

Reuse the parent's logic, then extend it.

When a subclass overrides a method, `super.method()` invokes the parent's original implementation.

↳ `super.method()` lets you call the overridden parent method from the child.

⚙️ Process

Constructor Chaining with this() and super()

Constructors calling constructors.

`this(...)` calls another constructor of the same class; `super(...)` calls a constructor of the parent class. Both must be the first statement in a constructor.

↳ Constructor chaining avoids code duplication and ensures proper initialization order.

💻 Code Example

this() Constructor Chaining in Action

One class, many constructors, no repetition.

↳ `this(...)` lets a no-arg constructor delegate to a parameterized one.

💻 Code Example

super() Constructor Chaining in Action

Initialize the parent first.

↳ `super(...)` ensures the parent's fields are initialized before the child's.

⚠️ Common Mistake

this() and super() Must Be First

Order matters in constructors.

↳ Constructor chaining calls must be the first statement — no exceptions.

⚠️ Common Mistake

Can't Use Both this() and super()

Pick one, not both.

↳ Only one constructor delegation call is allowed per constructor.

⭐ Important Fact

Default super() Is Inserted Automatically

Java does it for you.

If a constructor does not explicitly call `this(...)` or `super(...)`, the Java compiler automatically inserts a no-argument `super()` call — provided the parent has an accessible no-arg constructor.

↳ Silent `super()` insertion means the parent's no-arg constructor runs first by default.

🚫 Warning

super() Fails If Parent Has No No-Arg Constructor

Missing parent constructor breaks compilation.

↳ Always ensure the parent has a no-arg constructor or call `super(...)` explicitly.

🛠️ Application

Returning the Current Object with 'this'

Fluent APIs start here.

Returning `this` from a method enables method chaining, a common pattern in builders and fluent APIs.

↳ `return this;` is the backbone of fluent interfaces and builder patterns.

🎯 Exam Tip

Exam Favorite: this vs super Quick Recall

Two keywords, four uses.

↳ Memorize the four usage pairs — most exam questions test exactly these.

Smart notes

What you'll study, topic by topic

1

Java this and super Keywords

15 min

The this and super keywords in Java are reference variables that let an object refer to itself (this) and to its immediate parent class (super). They are essential for resolving naming conflicts, chaining constructors, a…

  • `this` refers to the current object instance; `super` refers to the parent-class view of that same object.
  • `this` is only valid in instance context — instance methods, constructors, and instance initializers.
  • `this` cannot be used inside a `static` method because no object is associated with it.

Full explanation, worked examples & memory tricks in the app

Leveled MCQ practice

Try the smart MCQs from this kit

All 17 questions, laddered from warm-up to topper-level, each with its answer and the reasoning behind it.

Warm-up · 7 questions

Q1. Which statement best describes the difference between `this` and `super`?

Beginner
A `this` is the parent object; `super` is the current object.
B `this` is the current object; `super` is the parent view of it.
C `this` is a variable; `super` is a keyword.
D `this` and `super` are two separate objects created at runtime.

Answers and explanations are in the Veda app.

Q2. Inside which of the following can `this` legally appear?

Beginner
A A static initializer block
B An instance method
C A static nested class's static method
D A static method

Answers and explanations are in the Veda app.

Q3. What does the statement `this.name = name;` do inside a constructor?

Beginner
A Assigns the field to the parameter
B Assigns the parameter to the instance field
C Assigns the parameter to itself
D Creates a new field named `name`

Answers and explanations are in the Veda app.

Q4. What is the required position of a `this(...)` constructor call within a constructor?

Beginner
A It must appear immediately after `super(...)`
B It can appear anywhere in the body
C It must be the last statement
D It must be the first statement

Answers and explanations are in the Veda app.

Q5. Which of these is a valid use of `this`?

Beginner
A Storing it in a variable: `Object o = this;` inside a static method
B Calling a grandparent method: `this.super.method();`
C Passing the current object to another method: `register(this);`
D Assigning a new object: `this = new Foo();`

Answers and explanations are in the Veda app.

Q6. Which statement about `this` and `super` is TRUE?

Beginner
A They refer to two distinct objects created at runtime.
B They are keywords, not variables, and cannot be reassigned.
C They are variables that can be reassigned to new objects.
D They can be used freely inside static methods.

Answers and explanations are in the Veda app.

Q7. Every constructor that does not explicitly call `this(...)` or `super(...)` receives an implicit `super()` call as its first statement, which is why a subclass fails to compile when the parent lacks a no-arg constructor.

Beginner
A True
B False

Answers and explanations are in the Veda app.

Building up · 5 questions

Q8. A `Student` class has field `name` and a constructor parameter also called `name`. The constructor body is just `name = name;`. What is the field's value after construction?

Intermediate
A It remains `null` (or its default), unchanged
B It equals the constructor argument
C It causes a compile error
D It causes a runtime exception

Answers and explanations are in the Veda app.

Q9. A subclass constructor writes neither `this(...)` nor `super(...)`. What does the compiler do?

Intermediate
A Leaves the constructor with no parent call
B Raises a compile error for the missing call
C Inserts an implicit `super()` as the first statement
D Inserts an implicit `this()` as the first statement

Answers and explanations are in the Veda app.

Q10. `Animal.speak()` returns `"..."`. `Dog` overrides `speak()` as `return super.speak() + " Woof";`. What does `new Dog().speak()` return?

Intermediate
A `"... Woof"`
B `"..."`
C `"Woof"`
D A compile error, since `super` cannot be used in a return

Answers and explanations are in the Veda app.

Q11. A class has constructors `Point()` and `Point(int x, int y)`. Which body correctly chains `Point()` to the two-arg constructor?

Intermediate
A `Point(0, 0);`
B `super(0, 0);`
C `this(0, 0);`
D `new Point(0, 0);`

Answers and explanations are in the Veda app.

Q12. In a subclass, `super.field` is used to access what?

Intermediate
A A subclass-only field not present in the parent
B A private field of the grandparent class
C A static field of the parent class
D A parent field hidden by a same-named subclass field

Answers and explanations are in the Veda app.

Topper level · 5 questions

Q13. The parent class `Animal` defines only `Animal(int age)`. A subclass `Dog` has a constructor with no explicit `super(...)` or `this(...)`. What happens?

Advanced
A Compiles fine; the parent's `age` defaults to 0
B Compilation fails: no matching no-arg parent constructor
C Compiles fine; the compiler picks `Animal(int)` automatically
D Compiles but throws at runtime when `Dog` is instantiated

Answers and explanations are in the Veda app.

Q14. Why does `super.super.method()` fail to compile?

Advanced
A `super` is a variable, so chaining is not allowed
B `super` reaches only the immediate parent, not the grandparent
C `super` can only be used in constructors, not methods
D `super` requires a cast to the grandparent type first

Answers and explanations are in the Veda app.

Q15. Which pair of statements about `this(...)` and `super(...)` is correct?

Advanced
A Each must be last; they can both appear in one constructor.
B Each must be first; they cannot both appear in one constructor.
C Neither has a position rule, but they cannot be combined.
D `this(...)` must be first, but `super(...)` may appear anywhere.

Answers and explanations are in the Veda app.

Q16. A developer overrides `equals` in a class and writes `return this.id == other.id;`. What role does `this` play here?

Advanced
A It refers to the current object being compared
B It creates a new instance for comparison
C It refers to the parent class's `id` field
D It is illegal inside `equals` and causes a compile error

Answers and explanations are in the Veda app.

Q17. Consider the following class definitions: ```java class Parent { Parent(int x) { } } class Child extends Parent { Child() { this(5); } Child(int x) { super(x); } } ``` What happens when you try to instantiate `Child` using `new Child();`?

Advanced
A A runtime error occurs due to the absence of a no-arg constructor in Parent.
B The Child object is created with the Parent constructor being called with 5.
C A compilation error occurs because `super()` is not called in the constructor.
D The code compiles successfully and creates a Child object.

Answers and explanations are in the Veda app.

Flashcards

Tap a card to flip it

20 flashcards in this kit — the app reviews them with spaced repetition so the right card returns on the right day.

Learning games

Play your way through this kit

Every game is built from this kit's own content — scores feed your mastery, so playing counts as studying.

🎮

Word Match

Built from this kit's own content

🎮

True False

Built from this kit's own content

🎮

Memory Match

Built from this kit's own content

🎮

Flashcard Battle

Built from this kit's own content

🎮

Speed Quiz

Built from this kit's own content

🎮

Guess Term

Built from this kit's own content

🎮

Sequence Builder

Built from this kit's own content

🎮

Categorization

Built from this kit's own content

🎮

Revision Battle

Built from this kit's own content

Playable in the app

Study it properly — free, in the app

The full Veda Bites deck, complete notes, spaced-repetition flashcards, leveled MCQs, tests and games for this kit — plus Daily Facts and the Arena, every day.