In Object Oriented world, if one class has to communicate with any other class (or classes), it has to
communicate by using one of the Object Oriented Relationships.
Inheritance or Generalization
Aggregation
o Weak
o Strong (Also called as Composition or Containment)
Association
Inheritance1
Inheritance is the process by which objects can acquire the properties of objects of other class.
In OOP, inheritance provides reusability. For example, adding additional features to an existing class
without modifying it. This is achieved by deriving a new class from the existing one. The new class will
have combined features of both the classes.
The main advantage of inheritance is the ability to define new attributes and new methods for the
subclass which are then applied to the inherited attributes and methods.
In the Zebra class, see how Horse works, and then define (override) the few things that are features
of Zebras but not Horses.
This is the key feature of inheritance -- arrange classes to factor out code duplication.
[2 Quoted from: Stanford CS108, Winter 09]
Example
Single Inheritance
Example