Need of Inheritance
Inheritance helps in representing
1.
Classes in hierarchy: well
organized problem solution space.
2.
Extending existing classes thus
promotes reuse.
3.
Reducing the duplication of
efforts.
Types Inheritance
in C++
1.
Singly Inheritance
2.
Multiple Inheritance
3.
Hierarchical Inheritance
4.
Multilevel Inheritance
5.
Hybrid Inheritance
It is
the process of creating a new class from an existing base class. The existing
class is known as the base class and the newly created class is called as a
derived class.
In
Singly Inheritance there is one base class and one derived class.
Singly
Inheritance is the ability of a derived class to inherit the member functions
and variables of the existing base class.
Multiple Inheritance
In the
multiple inheritance there are more than one base class and one derived class.
Multiple
inheritance can combine the behavior of multiple base classes in a single
derived class. Multiple inheritance has many advantages over the single
inheritance such as rich semantics and the ability to directly express complex
structures.
Hierarchical Inheritance
When two or more classes derive from a single class, then
inheritance is called the hierarchical inheritance.
Multilevel Inheritance
C++ also provides the facility of multilevel inheritance, according to which the derived class can also be derived from another class, which in turn can further be inherited by another and so on.
Multilevel Inheritance
C++ also provides the facility of multilevel inheritance, according to which the derived class can also be derived from another class, which in turn can further be inherited by another and so on.
No comments:
Post a Comment