9 - Inheritance Flashcards
Inheritance
is the process of deriving a new class from an existing one
One purpose of inheritance is …
to reuse existing software
Inheritance creates an …
is-a relationship between the parent and child classes.
Extends
Java keyword to indicate that a new class is being derived from an existing class.
Protected
allows derived classes to reference it. Provides encapsulation that permits inheritance.
Super
used in a class to refer to its parent class such as a class’s constructor.
single inheritance
Java’s approach to inheritance is called single inheritance, meaning a derived class can only have one parent.
A child class can override(redefine) …
the parent’s definition of an inherited method. Must have the same name and same signature.
Shadow variable
if a variable of the same name is declared in a child class.
class hierarchy
A child of one class can be the parent of one or more other classes
Common features should be located as high …
in a class hierarchy as is reasonable possible.
Object class
All Java classes are derived, directly or indirectly, from the Object class.
What methods are inherited by every class in a Java program?
toString
equals
An abstract class cannot …
be instantiated. It represents a concept on which other classes can build their definitions. They are like placeholders for all derived classes.
Abstract children and parent relationship…
A class derived from an abstract parent must override all of its parent’s abstract methods, or the derived class will also be considered abstract.