Kit Library / Computer Science / Object-Oriented Programming

⚡ Topic Learning Kit

this and super Keywords in Java

English 17 leveled MCQs 20 flashcards 9 games Free

Shared by a Veda teacher · 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

Two References, Two Directions

One points inward, one points upward.

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

↳ `this` = me; `super` = my parent. Both are implicit references available inside instance context.

📖 Definition

What Exactly Are this and super?

Not objects — reference variables.

Both are implicitly available inside non-static methods and constructors — you never declare them.

↳ They are predefined reference variables, not keywords you instantiate.

💡 Key Idea

Why this Exists: Shadowing Rescue

Same name, two meanings — this breaks the tie.

When a parameter or local variable has the same name as an instance variable, the local one shadows the field. `this.field` explicitly reaches the object's field.

↳ `this.x` always means the instance field, even when a local `x` exists.

💡 Key Idea

Why super Exists: Reaching the Parent

Override hides the parent — super brings it back.

When a subclass overrides a method or hides a field, `super.method()` and `super.field` still access the parent version.

↳ `super` gives access to the parent's implementation even after overriding.

⚙️ Process

Constructor Chaining with this()

One constructor calling another — cleanly.

`this()` invokes another constructor of the same class, reducing duplication.

↳ `this(...)` must be the **first statement** in the constructor.

⚙️ Process

Constructor Chaining with super()

Parent constructor runs before child.

`super(...)` invokes the parent class constructor and must be the first statement in the subclass constructor. If omitted, Java inserts `super()` automatically.

↳ Parent constructor always executes before the child's body.

⚠️ Common Mistake

Using this/super in Static Context

Static has no object — so this fails.

↳ No object → no `this`/`super`. Static context is object-free.

⚠️ Common Mistake

this() and super() Cannot Coexist

Only one can be first.

↳ First-statement rule means `this()` and `super()` are mutually exclusive in one constructor.

⚖️ Comparison

this vs super at a Glance

Side-by-side, no confusion.

↳ Same syntax shape, different target — memorize the target column.

✏️ Example

Real Scenario: Employee and Manager

Inheritance in action with both keywords.

↳ `super` is the standard tool for extending inherited behavior.

🛠️ Application

Where You'll Actually Use Them

Every framework uses these daily.

↳ These keywords are the backbone of OOP-style Java code.

✅ Best Practice

Return this for Chaining

Chain methods like a pro.

↳ `this` as a return value powers builder and fluent APIs.

🎯 Exam Tip

Exam Favorite: First-Statement Rule

Examiners love this trap.

↳ Four rules cover most exam questions on this topic.

🧠 Memory Trick

Remember It as 'Me vs My Parent'

Two words, one mental image.

this = me (current object). super = my parent (superclass). Whenever you're confused, ask: *am I talking about myself or my parent?*

↳ Anchor `this` to 'me' and `super` to 'parent' — resolves most confusion instantly.

🚫 Warning

super() Fails Without a No-Arg Parent Constructor

Missing parent constructor = compile error.

↳ Always ensure the parent has a constructor the child can call.

Smart notes

What you'll study, topic by topic

1

this and super Keywords in Java

18 min

The `this` and `super` keywords are reference variables in Java that let an object access its own members and its parent class members respectively. `this` resolves ambiguity between instance variables and parameters and…

  • `this` is a hidden reference to the current object, supplied automatically to instance methods and constructors.
  • Inside `s1.display()`, `this` refers to `s1`.
  • `this.field` disambiguates an instance field from a parameter or local variable with the same name.

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 · 6 questions

Q1. Inside an instance method, what does the `this` keyword refer to?

Beginner
A The method's local variables
B The class itself
C The current object
D The superclass object
Show the answer

C · The current object

`this` is a hidden reference to the object on which the method was invoked.

Q2. Which statement about `super` is correct?

Beginner
A It refers to the parent part of the current object
B It works in static methods
C It refers to a separate parent object
D It can be assigned to a variable
Show the answer

A · It refers to the parent part of the current object

`super` is a reference to the superclass slice within the current object, not a distinct object.

Q3. What is the purpose of `this.field = field;` in a constructor?

Beginner
A To create a new object
B To assign the parameter to the instance field
C To assign the field to the parameter
D To call the parent constructor
Show the answer

B · To assign the parameter to the instance field

`this.field` refers to the instance field, while `field` on the right is the parameter, resolving the name clash.

Q4. Which keyword must be the first statement in a constructor to call another constructor of the same class?

Beginner
A `super(...)`
B `this(...)`
C `super`
D `this`
Show the answer

B · `this(...)`

`this(...)` invokes another constructor of the same class and must be the first statement.

Q5. What does `super.method()` do?

Beginner
A Creates a new parent object
B Calls the parent's version of the method
C Calls the current class's version of the method
D Calls a static method in the parent
Show the answer

B · Calls the parent's version of the method

`super.method()` explicitly invokes the superclass's implementation of the method.

Q6. `this(...)` and `super(...)` must be the first statement in a constructor, and a constructor cannot contain both.

Beginner
A True
B False
Show the answer

A · True

`this(...)` and `super(...)` must be the first statement in a constructor, and a constructor cannot contain both.

Building up · 6 questions

Q7. Why is `this` not allowed in a static method?

Intermediate
A Static methods have no current object
B Static methods are always private
C Static methods cannot access instance fields
D `this` is only for constructors
Show the answer

A · Static methods have no current object

`this` requires an object instance; static methods belong to the class and have no instance.

Q8. Consider the code: ```java class A { void show() { System.out.println("A"); } } class B extends A { void show() { super.show(); System.out.println("B"); } } new B().show(); ``` What is printed?

Intermediate
A A then B
B Only B
C Only A
D B then A
Show the answer

A · A then B

`super.show()` calls the parent's `show()` first, printing "A", then the subclass prints "B".

Q9. What happens if a subclass constructor does not explicitly call `this(...)` or `super(...)`?

Intermediate
A Java inserts a hidden `this()` call
B The parent constructor is skipped
C Compilation error
D Java inserts a hidden `super()` call
Show the answer

D · Java inserts a hidden `super()` call

Java automatically inserts `super()` if no explicit constructor call is present, requiring the parent to have a no-argument constructor.

Q10. Which of the following is a valid use of `this`?

Intermediate
A Assigning `this` to another variable
B Returning `this` from a method for chaining
C Using `this` in a static block
D Calling `this.super.method()`
Show the answer

B · Returning `this` from a method for chaining

Returning `this` is a common pattern for method chaining; the other options are illegal.

Q11. What is the effect of declaring a field in a subclass with the same name as a field in the parent?

Intermediate
A The parent field is overwritten
B Compilation error due to duplicate field
C Both fields refer to the same memory
D The subclass field shadows the parent field
Show the answer

D · The subclass field shadows the parent field

Field shadowing creates two separate fields; `this.field` accesses the subclass field, `super.field` accesses the parent field.

Q12. In a constructor, which statement is true about `this(...)` and `super(...)`?

Intermediate
A A constructor can contain both, with `this(...)` first
B A constructor can contain at most one of them, as the first statement
C A constructor can contain both, with `super(...)` first
D A constructor can contain both, in any order
Show the answer

B · A constructor can contain at most one of them, as the first statement

Only one constructor call is allowed, and it must be the first statement.

Topper level · 5 questions

Q13. Why does Java require `this(...)` or `super(...)` to be the first statement in a constructor?

Advanced
A To enable method overriding
B To prevent recursive constructor calls
C To allow access to static members
D To ensure the object is initialised before other code runs
Show the answer

D · To ensure the object is initialised before other code runs

The first-statement rule guarantees that the object is fully constructed before any other statements execute.

Q14. A class `Child` extends `Parent`. `Parent` has only a constructor `Parent(int x)`. What must `Child`'s constructor do to compile?

Advanced
A Rely on the hidden `super()` call
B Call `this()` with an int argument
C Explicitly call `super(x)` as its first statement
D Declare a no-argument constructor in `Parent`
Show the answer

C · Explicitly call `super(x)` as its first statement

Since `Parent` lacks a no-argument constructor, the hidden `super()` would fail; `Child` must explicitly call `super(x)`.

Q15. What is the result of trying to use `super.super.method()`?

Advanced
A It calls the parent's method twice
B It is allowed only in static context
C Compilation error
D It calls the grandparent's method
Show the answer

C · Compilation error

`super.super` is illegal; you can only access one level up the inheritance hierarchy.

Q16. Which statement best explains why `super` cannot be passed as an argument to a method?

Advanced
A `super` is a keyword, not an object reference
B `super` is automatically null
C `super` is only valid in constructors
D `super` is private to the superclass
Show the answer

A · `super` is a keyword, not an object reference

`super` is a special keyword that refers to the parent slice; it is not a standalone object and cannot be stored or passed.

Q17. Given the following code, what will be the output when `new Dog().sound();` is executed?

Advanced
A Bark Some sound
B Bark
C Some sound Bark
D Some sound
Show the answer

C · Some sound Bark

The correct output is 'Some sound Bark' because `super.sound()` calls the parent method from `Animal`, which prints 'Some sound', followed by the subclass `Dog` printing 'Bark'.

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.