The world around us is made
of objects that share many similarities. These similarities can be classified
into common groups. For example, in biology taxonomy organisms are classified
into a hierarchy of group, from general to specific. In C++, objects are
created from classes; and a class may share (inherit) some common data members
and member functions that belong to another class or classes. As a result, a
new class can be created based on an existing class rather than creating it
from scratch. An inherited class can have its own data and function members
and can modify or override the inherited members. Inheritance is an important
tool of Object-Oriented Programming (OOP), because it promotes reusability and
ease of extensibility by building on what is already there and customizing it
as desired. A programmer can build a hierarchy that goes from a general class
to a specific class by incorporating inheritance. With class hierarchy a
program is easier to follow, debug, and modify. With inheritance, a class is
built on an existing class that has already been tested; therefore,
inheritance reduces the time and the cost of development as well as minimizes
errors in the program. Inheritance is also known as derivation
or specialization. In fact, inheritance is not something new.
For example, humans have organized knowledge into hierarchical structures such
as the animal kingdoms.