Inheiritance+Concepts

**Introduction**
Inheritance is a mechanism which simplifies the definition of a new class which is similar to an existing class. Inheritance is an important mechanism in support of code sharing and software re-use. Rather than creating a completely new class the programmer inherits the properties and characteristics of an existing class. A derived class can add data members and member functions of its own, so a derived class can be larger than its base class.

**1.0 What are base classes and derived classes?**
A base class expresses a general concept of which all derived classes are specialized. An object of the derived class may use the services of a member function of the base class as if it were defined for that class. Each derived class itself becomes a candidate to be a base class for some future derived class. The real strength of inheritance comes from the ability to define in the derived class additions, replacements or refinements to the features inherited from the base class. Syntax for deriving a class Y from a class X

 Class Y : public X{…..…};

Here X is call the base class and Y is called the derived class. The keyword public specifics a public inheritance, which means that the public data members and functions of the base class become public members and functions of the derived class.

**2.0 Inheritance Type**
Base Member Access Public PrivatePublic Inherited as public Inherited as privateProtected Inherited as protected Inherited as privatePrivate Not accessible Not accessible We will not be using private inheritance.

**3.0 Multiple Inheirtance**
Single VS Multiple Inheritance What you seen above is an example of single inheritance. With single inheritance, a class is derived from one base class. With multiple inheritance, a derived class inherits from multiple base classes. Single inheritance is straight forward. Multiple inheritance is complex and error prone, I must issue a strong caution urging you to pursue further study before using this powerful capability.

Note that even for single inheritance, care must be taken when designing a derived class this way. The derived class must be a subset of the base class.

**4.0 Conclusion**
In object-oriented programming, inheritance is the concept that when a class of objects is defined, any subclass that is defined can inherit the definitions of one or more general classes. This means for the programmer that an object in a subclass need not carry its own definition of data and methods that are generic to the class (or classes) of which it is a part. This not only speeds up program development; it also ensures an inherent validity to the defined subclass object (what works and is consistent about the class will also work for the subclass).