Unit 9 - Inheritance Flashcards
Superclass
Class hierarchy can be developed by putting common attributes & behaviors of related classes into a single class
Subclasses
Extend a superclass Can draw upon existing attributes & behaviors of superclass without repeating in code
Extending a subclass from a superclass creates an
"is-a" relationship from subclass to superclass (Lower class) is a (Upper class)
Inheritance
Parent classes have attributes & behaviors that can be inherited by child classes
Why use inheritance
Code reusability
Prevents repeating code
Readability & organization
Ease of maintenance
Each subclass can only have
one superclass
All subclasses inherit
attributes and methods of their superclasses
A superclass can’t
inherit attributes and methods of subclass implicitly
keyword extend
Used to establish an inheritance relationship between subclass and a superclass Can only extend one superclass
Constructors are
NOT inherited
When a subclass’s constructor does not explicitly call a superclass’s constructor using super,
Java inserts a call to superclass’s no-argument constructor
Superclass constructor can be called from first line of subclass constructor by using
keyword super and passing appropriate parameters
Actual parameters passed in call to superclass constructor provides
values that constructor can use to intialize the object’s instance variabes
Using super will call
No-argument constructor of superclass MUST be the first line of body of constructor
Whether superclass constructor is called implicitly or explicitly, process of calling superclass constructors continue up
inheritance hierarchy with each constructor calling constructor of superclass until Object constructor is called