Types of inheritance
1.
Single inheritance
2.
Multiple inheritance
3.
Heretical inheritance
4.
Multilevel inheritance
5.
Hybrid inheritance
Single inheritance:
it has single base class and single derived class it
consists of at least 2 classes
example:
animal derived from leaving things
car derived from vehicle
program:
in this example a single base and child classes exist so it is single
inheritence
multiple inheritance:
in this type of inheritance, a single child class derived from two or more
classes
example:
petrol derived from liquid and fuel
child class derived from mother and father
example program:
#include<iostream>
Using namespace std;
Int main ()
{
Class father
{
};
Class mother
{
};
Class child: public father, mother
{
};
error ambiguity or diamond problem
sample A: display ();
sample. b: display ();
hieratical inheritance:
in this type of inheritance
multiple child classes inherits from a single parent class
example:
civil, mechanical and
electrical derived from engineer
class
multilevel inheritance:
in this type of inheritance,
the derived class inherit from a class that inherited from another derived
class
child father
grandfather
hybrid inheritance:
hybrid inheritance is a
method where one or more types of inheritance are combined together
No comments:
Post a Comment