this and super Keywords in Java: 17 MCQs with answers

All 17 multiple-choice questions from this kit, free and with no sign-up.

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'.

Make your own

Your notes can be a kit like these

Every kit here was made from real study material. Point Veda at a chapter, a PDF, a photo or a link and get notes, flashcards, practice MCQs, games and a scored test — free, in 42 languages.

  • Chapter notes
  • Flashcards
  • Practice MCQs
  • Scored tests
  • Exam prep

Get Veda free See what students get

Free to start · No ads · Works in 42 languages