Java this and super Keywords: 17 MCQs
All 17 multiple-choice questions from this kit, free and with no sign-up.
Warm-up · 7 questions
Q1. Which statement best describes the difference between `this` and `super`?
BeginnerAnswers and explanations are in the Veda app.
Q2. Inside which of the following can `this` legally appear?
BeginnerAnswers and explanations are in the Veda app.
Q3. What does the statement `this.name = name;` do inside a constructor?
BeginnerAnswers and explanations are in the Veda app.
Q4. What is the required position of a `this(...)` constructor call within a constructor?
BeginnerAnswers and explanations are in the Veda app.
Q5. Which of these is a valid use of `this`?
BeginnerAnswers and explanations are in the Veda app.
Q6. Which statement about `this` and `super` is TRUE?
BeginnerAnswers 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.
BeginnerAnswers 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?
IntermediateAnswers and explanations are in the Veda app.
Q9. A subclass constructor writes neither `this(...)` nor `super(...)`. What does the compiler do?
IntermediateAnswers 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?
IntermediateAnswers 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?
IntermediateAnswers and explanations are in the Veda app.
Q12. In a subclass, `super.field` is used to access what?
IntermediateAnswers 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?
AdvancedAnswers and explanations are in the Veda app.
Q14. Why does `super.super.method()` fail to compile?
AdvancedAnswers and explanations are in the Veda app.
Q15. Which pair of statements about `this(...)` and `super(...)` is correct?
AdvancedAnswers 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?
AdvancedAnswers 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();`?
AdvancedAnswers and explanations are in the Veda app.
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