Inheritance
Notes on Inheritance (Full Set)
- Inherited state and methods are not repeated in subclass.
- Superclass may be complete class (can instantiate).
- Superclass may be abstract
(incomplete; cannot instantiate).
- In subclass, invoke superclass constructor with
super()
"method".
- A redefined method (same signature, new body)
overrides method from superclass; redefined
method is executed instead.
- In redefined method, invoke overridden superclass method with
super.method()
.
- Polymorphism means that
may be used where objects of the superclass are expected.
- Dynamic binding means that the right
method will be called.
private
: instance variables & methods cannot be
accessed/used directly by the subclass
public
: can be accessed/used by subclass (or anyone)
protected
: accessible to class and
its subclasses, but not to other classes (new keyword)
Alyce Brady, Kalamazoo College