Inheritance 1
Inheritance 1
Syllabus
Inheritance: Defining derived classes, Single Inheritance, Making a
private member inheritable, Multilevel, Multiple inheritance, Hierarchical
inheritance, Hybrid inheritance, Virtual base classes, Abstract classes,
Constructors in derived classes, Member classes - Nesting of classes.
2. Multiple Inheritance:
Derived class inherits only from multiple base classes.
3. Hierarchical Inheritance:
More than one derived are created from a single class base classes.
4. Multilevel Inheritance:
When a class is derived from a class which is a derived class.
5. Hybrid Inheritance:
Combination of more than one type of inheritance.
6. Multipath Inheritance:
Derivation of a class from other derived classes, which are derived from the same base class.
SINGLE INHERITANCE
Inheritance in which the derived class is derived from only one base class.
Ex: Program shows a base class B and a derived class D.
The class B contains one private data member, one public data member and three
public member functions.
The class D contains one private data member and two public member functions.
Single Inheritance – Public Inheritance
Single Inheritance – Public Inheritance
Single Inheritance – Public Inheritance
Single Inheritance – Public Inheritance
Class D is a public derivation of the base class B.
D inherits all the public members of B and retains
their visibility.
A public member of the base class is also a public
member of the derived class D.
The private members of B cannot be inherited by
D.
Class D have more members than what it
contains at the time of declaration.
Data member a is private in B and cannot be
inherited, objects of D are able to access it
through an inherited member function of B
Single Inheritance – Private Inheritance