- Inheritance = reuse: a new class absorbs an existing class’s members and adds or modifies some.
- Existing class = superclass; new class = subclass (extends).
🎯 How this can come up · 1 question
Which keyword makes a class inherit from another?
Correct: extends.
- Direct superclass: the one you extend. Indirect: higher up. Every class ultimately extends Object.
🎯 How this can come up · 1 question
Java supports multiple inheritance of classes (a class can extend two classes).
False. Single inheritance; use interfaces for more.
- Superclasses are more general, subclasses more specific; a subclass object IS-A superclass object.
- is-a = inheritance (a Car is a Vehicle). has-a = composition (a Car has an Engine).
🎯 How this can come up · 1 question
“A Manager is an Employee” suggests:
Correct: Inheritance.
- A subclass may inherit methods it doesn’t want; it can override them.
- Without inheritance, BasePlusCommissionEmployee copies almost all of CommissionEmployee.
- Constructors are NOT inherited. A subclass constructor must call a superclass constructor first (explicitly with super(...) or implicitly).
🎯 How this can come up · 1 question
Constructors are inherited by subclasses.
False.
- Overriding: same signature in the subclass; @Override asks the compiler to check it.
🎯 How this can come up · 1 question
A subclass method with the same signature as a superclass method:
Correct: Overrides it.
- Copy-and-paste reuse is error-prone and a maintenance nightmare → use inheritance.
- class BasePlusCommissionEmployee extends CommissionEmployee: only the base salary is new.
- super(args) must be the FIRST statement in the subclass constructor.
🎯 How this can come up · 1 question
Where must the call super(first, last, ssn) appear in a subclass constructor?
Correct: As the first statement.
- A subclass can’t access the superclass’s PRIVATE fields directly → use get methods (or protected).
🎯 How this can come up · 1 question
A subclass can directly read its superclass’s private instance variables.
False. Use getters or protected access.
No slides match this filter.