Java this and super Keywords: 20 flashcards
All 20 flashcards from this kit, free and with no sign-up.
1. What does `this` refer to in Java?
Show the answer
The current object instance whose method or constructor is executing.
2. What does `super` refer to in Java?
Show the answer
The immediate parent-class view of the current object.
3. In which contexts is `this` valid?
Show the answer
Instance methods, constructors, and instance initializer blocks — any non-static instance context.
4. Why can't `this` be used inside a `static` method?
Show the answer
A static method belongs to the class, not to any object, so there is no current instance to reference.
5. What does `this.name = name;` accomplish?
Show the answer
It assigns the constructor parameter `name` to the instance field `name`, resolving shadowing.
6. What happens with `name = name;` when a parameter shadows a field?
Show the answer
The parameter is assigned to itself; the instance field stays unchanged (often `null`).
7. What does `this(args)` do in a constructor?
Show the answer
Calls another constructor of the same class with the given arguments.
8. Where must a `this(...)` call appear in a constructor?
Show the answer
As the very first statement of the constructor.
9. What does `super(args)` do?
Show the answer
Invokes a constructor of the immediate parent class with the given arguments.
10. Can `this(...)` and `super(...)` appear in the same constructor?
Show the answer
No — they are mutually exclusive; only one may appear, and it must be first.
11. What does the compiler insert if neither `this(...)` nor `super(...)` is written?
Show the answer
An implicit `super()` call as the first statement of the constructor.
12. What happens if the parent has no no-arg constructor and the subclass doesn't call `super(args)`?
Show the answer
Compilation fails, because the implicit `super()` cannot find a matching parent constructor.
13. What does `super.method()` do?
Show the answer
Invokes the parent class's version of an overridden method.
14. What does `super.field` do?
Show the answer
Accesses a parent field that is hidden by a subclass field of the same name.
15. Is `super.super.method()` legal in Java?
Show the answer
No — only the immediate parent is reachable via `super`.
16. Are `this` and `super` variables or keywords?
Show the answer
They are keywords, not variables — they cannot be reassigned or assigned to a reference variable.
17. What does `return this;` enable?
Show the answer
Fluent APIs and builder patterns, by returning the current instance for chaining.
18. Why is `super.onCreate(...)` required in Android lifecycle overrides?
Show the answer
Skipping it discards the parent's required lifecycle setup and can crash the app.
19. What is the mental model for `this` vs `super`?
Show the answer
One object, two lenses: `this` sees the whole subclass instance; `super` sees only the parent slice.
20. Can constructor chaining via `this(...)` form a cycle?
Show the answer
No — a constructor cannot directly or indirectly call itself; that would be a compile error.
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