Inheritance in C++ Language( part 2)
Inheritance in C++ Language
Please, before see this part, please take a look at the previous part 1 so that you can understand better this part.Inheritance in C++ Language (part 1)
Types of Inheritance in C++ Language
- Single Inheritance
- Multilevel Inheritance
- Multiple Inheritance
- Hierarchical Inheritance
- Hybrid Inheritance
Single Inheritance :
A derived class with only one base class is called Single Inheritance.
Syntax :
Multilevel Inheritance :
A derived
class with one base class and that base class is a derived class of another is
called multilevel inheritance.
Syntax :
Multiple Inheritance :
A derived
class with multiple base class is called multiple inheritance.
Syntax:
Hierarchical Inheritance :
Multiple
derived classes with same base class is called hierarchical inheritance.
Syntax :
What is visibility mode
The are three type of mode :private,protected and public as seen in below:-In any class, you make these three types of modes,depending on you which member you will make
private,protected and public.
There are type of user of a class i.e The first user of two types of user is made the object of your class and second user will build a child(derived) class with the help of your base (parent)class.
Remember, the difference between Availability and Accessibility :-
Availability means that all three modes i.e private,protected and public are available in the storage space But the user 1 can access the public only but user 2 can access both protected and public therefore you can say that Accessibility means which can used by user or you can say that all three modes remain present but user 1 can used just public and user 2 can used protected and public.Let's see use of Visibility modes i.e Private , Protected and Public :
From the chart above (we take only user 2 example i.e derived class or child class), we can see the uses three modes separately . For example :-
1- If you used private mode in derived class i.e class B:private class A then derived class accesses protected and public both member of the parent class but its used as private member in its class
as we seen in above chart.
2- If you used protected mode in derived class i.e class B:protected class A then derived class accesses protected and public both member of parent class but its used as protected member in
its class.
3- If you used protected mode in derived class i.e class B:public class A then derived class accesses protected and public both member of parent class but its used protected member as
protected member and public member as public member in its class.
If this article is helpful to you then please like share and comments.
Thank you...
Comments
Post a Comment