A
class hierarchy
refers to a set of classes that are related by inheritence.
A relationship that can be describe as Xhas aY commonly indicates that X is a class and Y is a data member or member
function of the class.
A relationship that can be describe as Ais aB commonly indicates that A and B are both classes, and B is a super
class of A.
In this case, A is considered a
child
class and B is considered the
parent
class.
A good way to think if it is that the child class is a specialized
version of the parent class.
When designing a class hierarchy, you should push the more general
characterics farther up the hierarchy.
This includes both noun characteristics (data members) and verb
characterstics (member functions).
If a class farther down in the hierarchy needs different behavior,
you can
override
the member functions, and either completely replace or augment the corresponding
member function in the superclass.
In Java, the syntax for creating a child class is to use the keyword
extends
public class LabelledLine extends Line
Any public member functions that are not overidden in the
derived class will be inherited from the super class.
If you have a method whose implemented is not necessarily needed in the parent, but you want it for using
polymorphism, you can make it an abstract method.