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?
BeginnerShow 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?
BeginnerShow 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?
BeginnerShow 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?
BeginnerShow the answer
B · `this(...)`
`this(...)` invokes another constructor of the same class and must be the first statement.
Q5. What does `super.method()` do?
BeginnerShow 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.
BeginnerShow 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?
IntermediateShow 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?
IntermediateShow 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(...)`?
IntermediateShow 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`?
IntermediateShow 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?
IntermediateShow 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(...)`?
IntermediateShow 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?
AdvancedShow 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?
AdvancedShow 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()`?
AdvancedShow 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?
AdvancedShow 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?
AdvancedShow 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'.
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