Chapter 7 – Inheritance Flashcards
inheritance
Inheritance means that a very general form of a class can be defined and compiled. Later, more specialized versions of that class may be defined by starting with the already defined class and adding more specialized instance variables and methods. The specialized classes are said to inherit the methods and instance variables of the previously defined general class.
A derived class automatically has all the instance variables, all the static variables, and all the public methods of the base class. These members from the base class are said to be inherited. These inherited methods and inherited instance and static variables are, with one exception, not mentioned in the definition of the derived class, but they are automatically members of the derived class. The one exception is as follows: As explained in the subsection “Overriding a Method Definition,” you can give a definition for an inherited method in the definition of the derived class; this will redefine the meaning of the method for the derived class.
derived class
A derived class is a class defined by adding instance variables and methods to an existing class.
base class
The existing class that the derived class is built upon is called the base class.
extends
The way we indicate that HourlyEmployee is a derived class of Employee is by including the phrase extends Employee on the first line of the class definition, like so: >public class HourlyEmployee extends Employee
subclass and superclass
A derived class is also called a subclass, in which case the base class is usually called a superclass. However, we prefer to use the terms derived class and base class.
parent class
A base class is often called the parent class.
child class
A derived class is then called a child class.
ancestor class
A class that is a parent of a parent of a parent of another class (or some other number of “parent of” iterations) is often called an ancestor class.
descendent class
If class A is an ancestor of class B, then class B is often called a descendent of class A.
overriding
A derived class inherits methods that belong to the base class. However, if a derived class requires a different definition for an inherited method, the method may be redefined in the derived class. This is called overriding the method definition.
covariant return type
When overriding a class method in a derived class, you are not allowed to change the return type of the method, and you can’t make a void return non-void or vice versa. An exception to this changed return type is known as a covariant return type: when you override the function definition in a derived class that returns a class, you may change the returned type.
super
.
this
.
“is a” relationship
.
subclass and superclass
.