this and super Keywords in Java: 20 flashcards
All 20 flashcards from this kit, free and with no sign-up.
1. What does `this` refer to inside an instance method?
Show the answer
A hidden reference to the current object — the object on which the method was called.
2. In `s1.display()`, what does `this` mean inside `display()`?
Show the answer
`this` refers to `s1`.
3. How does `this.field` resolve a name clash?
Show the answer
It explicitly refers to the instance field, distinguishing it from a parameter or local variable with the same name.
4. What is the syntax to call another constructor of the same class?
Show the answer
`this(...)` — it must be the first statement in the constructor.
5. Can a constructor contain both `this(...)` and `super(...)`?
Show the answer
No. A constructor can have at most one of them, and it must be the first statement.
6. How is `this` used to enable method chaining?
Show the answer
A method returns `this`, so subsequent calls can be chained on the returned object.
7. Why can't `this` be used in a static method?
Show the answer
Static methods belong to the class, not an object, so there is no current object for `this` to refer to.
8. What does `super` refer to?
Show the answer
The parent part (superclass slice) of the current object — not a separate object.
9. How do you call the parent's version of an overridden method?
Show the answer
`super.methodName()`
10. How do you access a parent field that is shadowed by a subclass field?
Show the answer
`super.fieldName`
11. What does `super(...)` do?
Show the answer
Invokes a constructor of the immediate superclass; it must be the first statement in the subclass constructor.
12. What happens if a constructor has no explicit `this(...)` or `super(...)`?
Show the answer
Java automatically inserts a hidden `super()` call, requiring the parent to have an accessible no-argument constructor.
13. Is `super.super.method()` legal?
Show the answer
No. You can only go one level up the inheritance hierarchy.
14. Can `super` be assigned to a variable or passed as an argument?
Show the answer
No. `super` is a keyword, not an object reference; it cannot be stored or passed.
15. Why must `this(...)` or `super(...)` be the first statement in a constructor?
Show the answer
To guarantee the object is fully initialised before any other code in the constructor runs.
16. What is field shadowing?
Show the answer
When a subclass declares a field with the same name as a parent field, creating two separate fields in the same object.
17. How do custom exceptions commonly use `super`?
Show the answer
They call `super(message)` to pass the error message to the parent exception class.
18. In UI frameworks, what is a common use of `super`?
Show the answer
Calling `super.paintComponent(g)` before custom drawing to let the parent do its painting first.
19. What is a common use of `this` in event handling?
Show the answer
Passing `this` to a listener or manager to register the current object.
20. What is the difference between `this` and `super` in one line?
Show the answer
`this` refers to the current object; `super` refers to the parent part of that same object.
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