Inheritance is a very useful mechanism in software development, which is used to create the class hierarchy of an object oriented system.
defines inheritance as
[BOO91, p. 514]
Note that Java does not support multiple inheritance by definition. Due to that fact, it will not be described here.
Inheritance offers great advantages for software development:
» reusability: The methods and variables once defined in a class, can be used or extended by all subclasses of that class.
» reliability: Methods that worked in the superclass will also work the same way in each inherited class.
Example: Subclasses of the class "Car"
Although a sports car is unlike a truck, they both have something in common and thus were defined to be subclasses of a "Car". For example, both types have "a number of wheels" and also can be "accelerated". As can be seen, only the variables and methods specific for one type had to be added in the subclass.
The common methods (defined in Car) may be used by instantiated objects of the subclasses and must not be rewritten. By defining further subclasses, a class hierarchy arises, where classes in the lower part are more and more specialized. On the other hand, classes in the upper part are more generalized.
This leads us to another aspect of object orientation, which is called abstraction.