Inheritance: It is a process in which child class acquires the properties of parent class.
There are 5 types of Inheritance in C++
i. Single Inheritance
ii. Multiple Inheritance
iii. Multilevel Inheritance
iv.Hierarchical Inheritance
v. Hybrid Inheritance
Visibility Mode in Inheritance
There are three kinds of visibility mode in Inheritance
i.Public Mode
ii. Protected Mode
iii. Private Mode
These mode are explained below
**************************************************
i. Public Mode:
If the parent class is inherited by child class in public mode,public members of parent class become public members and protected members become protected members for child class.i.e public members of parent class are accssed by public members of child class and same goes for protected members.
ii. Protected Mode:
If parent class is inherited by child class in protected mode ,public members and protected membes of parent class are accessed or inherited by protected members of child class.
iii. Private Mode:
If parent class is inherited by child class in private mode ,public members and protected membes of parent class are accessed or inherited by private members of child class.
********************************************************
Inheritance types are explained below.
i. Single Inheritance:
The inheritance in which the properties of parent class is acquired by single(only one) child class is called single inheritance. i.e only one child class can be formed in it.
syntax: class Parent
{
code related to parent class
}
class Child : visibility mode(public,private,protected) Parent
{
code specific to child class
};
ii. Multiple Inheritance:
The inheritance in which the multiple parent class properties or member functions are inherited or acquired by single child class.In simple word,only one child class is derived or obtained from more than one parent class.
syntax: class ParentOne
{
code related to ParentOne;
};
class ParentTwo
{
code related to Parent Two;
}
class Child : visibility mode ParentOne,visibility mode ParentTwo
{
code related to child
} ;
iii. Multilevel Inheritance:
In this inheritance,the properties of parent class is inherited by child class and again the properties of child class is inherited by another child classone and this contiues.Here,the child classone acquires the properties of both child class and parent class.
syntax: class Parent
{
code specific to parent
};
class Child: visibility mode Parent
{
code related to child
};
class ChildOne : visibility mode Parent,visibility mode Child
{
code related to ChildOne
};
Comments
Post a Comment