Inheritance:-
The process of creating a new class from an old class with some additional feature is known as Inheritance.For example when Parent give birth to their children then children takes some feature of parent by default. In this situation Parent also don’t know what they have given to their children.
But in the concept of Inheritance , We can do as we want or according to our requirements. We can reuse the features of old class , as many as we want.
There are following Types of Inheritance.
- Single
- Multi Level
- Multiple
- Hierarchical
- Hybrid
SINGLE :-
- An inheritance in which a single class inherits the other one old class is known as Single Inheritance.This form of inheritance is implemented by defining two classes . One class which inherits other class is known as Base Class/Parent Class/Super Class. The class that is old or reused is known as Derived Class/Child Class/Sub Class.
Syntax,
class der_class_name: access_specifier baseclass
{
……………………………………………
……………………………………………
};
Example,
#include<iostream.h>
#include<conio.h>
class Acc
{
public:
float sal = 5000;
};
class Designer: public Acc {
public:
float gift = 500;
};
void main()
{
Designer p1;
cout<<“Sal: “<<p1.sal<<endl;
cout<<“Gift: “<<p1.gift<<endl;
}
Output:
Sal: 5000
Gift: 500
MULTI LEVEL :-
An inheritance in which a class inherits the other old class, also the class that is inheriting a class will inherited by other class and so on , this type of Inheritance is known as Multi Level Inheritance.This form is implemented by defining more than two classes .
In other words we can say , It is also possible to derive a class from an existing derived class . This form is known as multilevel inheritance . It is implemented by defining atleast three classes .
Syntax,
class der_class1_name: access_specifier baseclass1
{
……………………………………………
……………………………………………
};
class der_class2_name: access_specifier der_class1_name
{
……………………………………………
……………………………………………
};
class der_class3_name: access_specifier der_class2_name
{
……………………………………………
……………………………………………
};
Example,
#include<iostream.h>
#include<conio.h>
class person
{
char name [25];
long int pno;
public:
void read ()
{
cout<<” Enter name and pno = “;
cin>>name>>pno;
}
void display ()
{
cout<<” \nName = “<<name;
cout<<”\nPhone number = “<<pno;
}
};
class student: public person
{
int rno;
char course [25];
public:
void read()
{
person:: read ();
cout<<”Enter rno and course =”;
cin>>rno >>course;
}
void display ()
{
person:: display();
cout<<” \n rno = “<<rno;
cout<<” \n course = “<<course;
}
};
class exam: public student
{
int m[5];
double per;
public :
void read ();
void cal ();
void display ();
};
void exam: read()
{
student :: read () ;
cout<<” Enter marks:”;
for(int i=0; i<4; i++)
cin>>m[i];
}
void exam:: cal ()
{
int totmarks=0;
for(int i=0; i<4; i++)
totmarks += sum[i];
per=double (totmarks)/4;
}
void exam:: display()
{
student:: display ();
cout<<” nMarks : “;
for(int i=0; i<4; i++)
cout<<” \n Percentage = “<<per;
}
void main()
{
clrscr ();
exam e1;
e1.read ();
e1.cal ();
e1.dispaly();
getch();
}
MULTIPLE :-
An inheritance in which a class inherits the other two or more old classes, is known as Multiple Inheritance.This form of inheritance is implemented by defining more than two classes .
In this more than one base classes and one derived class is available.
In other words we can say , It is also possible to derive a class from more than one class . This form of inheritance is known as multiple inheritance . It is implemented by defining atleast three classes .
Syntax ,
class der_class_name: access_specifier baseclass1, access _specifier baseclass2, ……………
{
……………………………………………
……………………………………………
};
Example,
#include<iostream.h>
#include<conio.h>
class mybase1
{
protected:
int x;
public:
void readx()
{
cout<<” enter value of x :”;
cin>>x;
}
void showx()
{
cout<<” x = “<<x;
}
};
class mybase2
{
protected :
int y;
public;
void ready()
{
cout<<” enter value of y: “;
cin>>y;
}
void showy()
{
cout<<” \ny = “<<y;
}
};
class der: public mybase1,public mybase2
{
int z;
public:
void add()
{
z=x+y;
}
void showz()
{
cout<<” \nz = “<<z;
}
};
void main()
{
clrscr();
der d1;
d1.readx ();
d1.ready();
d1.add ();
d1.showx();
d1.showy();
d1.showz();
getch();
}
HIERACHICAL :-
An inheritance in which more than one class inherits the other one old class, is known as Hierachical Inheritance.This form of inheritance is implemented by defining more than two classes .In this one base and more than one derived classes are available.
In other words we can say , It is also possible to derive more than one class from an one old class . This form is known as Hierachical . It is implemented by defining atleast three classes .
Syntax,
class der_class1_name: access_specifier baseclass1
{
……………………………………………
……………………………………………
};
class der_class2_name: access_specifier baseclass1
{
……………………………………………
……………………………………………
};
class der_class3_name: access_specifier baseclass1
{
……………………………………………
……………………………………………
};
Example,
#include<iostream.h>
#include<conio.h>
using namespace std;
class Design
{
public:
int a;
int b;
void finddata(int n, int m)
{
a= n;
b = m;
}
};
class Rect : public Design
{
public:
int rectarea()
{
int result = a*b;
return result;
}
};
class Triangle : public Design
{
public:
int triarea()
{
float result = 0.5*a*b;
return result;
}
};
void main()
{
Rect r;
Triangle t;
int length,breadth,base,height;
std::cout << “Enter the length and breadth of a Rect: ” << std::endl;
cin>>length>>breadth;
r.finddata(length,breadth);
int m = r.rect_area();
std::cout << “Area of the Rect is : ” <<m<< std::endl;
std::cout << “Enter the base and height of the triangle: ” << std::endl;
cin>>base>>height;
t.finddata(base,height);
float n = t.triangle_area();
std::cout <<“Area of the triangle is : ” << n<<std::endl;
getch();
}
Output:
Enter the length and breadth of a Rect:
23
20
Area of the Rect is : 460
Enter the base and height of the triangle:
2
5
Area of the triangle is : 5
You Also Can Visit For More Knowledge In C++:-
Visit Your YouTube Channel:- Think , About It
Visit Your Website :- www.atozlives.com
Thanks,
“Play With All Computer Science , Mathematics And Technology.”
first class
Before Inheritance is very hard for me but after very easy for me
Like!! I blog frequently and I really thank you for your content. The article has truly peaked my interest.
Very good article! We will be linking to this great article on our website. Keep up the great writing.
You should participate in a contest for among the finest blogs on the web. I will advocate this website!
Once I initially commented I clicked the -Notify me when new comments are added- checkbox and now every time a comment is added I get 4 emails with the identical comment. Is there any approach you possibly can remove me from that service? Thanks!
There may be noticeably a bundle to find out about this. I assume you made certain good factors in options also.
The next time I read a weblog, I hope that it doesnt disappoint me as much as this one. I mean, I do know it was my option to learn, but I truly thought youd have one thing attention-grabbing to say. All I hear is a bunch of whining about something that you might fix if you happen to werent too busy looking for attention.
I definitely wanted to compose a comment to be able to thank you for the pleasant hints you are showing on this website. My rather long internet look up has now been recognized with excellent insight to exchange with my family members. I ‘d assume that many of us website visitors actually are undeniably lucky to exist in a good community with so many marvellous professionals with very beneficial solutions. I feel rather blessed to have encountered your entire webpages and look forward to really more fun moments reading here. Thank you again for everything.
My wife and i felt now contented that Michael managed to carry out his web research because of the ideas he discovered from your very own web site. It’s not at all simplistic just to find yourself handing out secrets and techniques that many some people have been selling. And we all fully grasp we now have the writer to thank because of that. Those explanations you’ve made, the straightforward blog navigation, the friendships your site make it possible to instill – it is everything powerful, and it’s really making our son in addition to us reason why this article is excellent, and that’s really serious. Thanks for everything!
What a data of un-ambiguity and preserveness of valuable experience
regarding unexpected emotions.
Hello i am kavin, its my first time to commenting anyplace, when i read this post i thought i could also make
comment due to this sensible post.
I don’t even know how I stopped up here, however I thought this
publish used to be great. I do not understand who you
are but definitely you’re going to a famous blogger in case you aren’t already.
Cheers!
I’m also writing to make you understand of the terrific experience my princess found browsing yuor web blog. She learned so many pieces, which included how it is like to possess an amazing teaching mindset to let the mediocre ones very easily learn a number of multifaceted subject areas. You undoubtedly surpassed my expectations. Thanks for producing the powerful, dependable, educational as well as unique tips about your topic to Ethel.
I’m writing to make you know of the great experience my cousin’s daughter went through viewing your blog. She mastered so many things, which include what it’s like to possess a very effective giving mood to make most people quite simply learn about specific tortuous things. You really did more than her expected results. Many thanks for showing such warm and helpful, healthy, explanatory as well as unique tips on this topic to Janet.
I intended to create you this little bit of observation so as to give thanks again for all the marvelous concepts you’ve featured here. It was really surprisingly generous with you to give publicly exactly what many of us could possibly have sold for an ebook to make some dough on their own, mostly considering that you might well have done it if you considered necessary. The tricks in addition served to be a fantastic way to realize that the rest have the same fervor really like mine to understand somewhat more in respect of this condition. I’m certain there are numerous more pleasurable moments in the future for individuals who view your website.
Wow, wonderful blog layout! How long have you been blogging for? Annnora Dalis Posehn
Congratulations on your blogging anniversary. I hope you get the chance soon for some new adventures. Ivy Mort Mazurek
good post, i surely enjoy this website, continue on it. Christyna Benjy Groscr
Hi there friends, its impressive article concerning teachingand completely defined, keep it up all the time. Mellie Griffin Braden Collie Ambrose Aunson
Thank you for your own effort on this website. My aunt takes pleasure in managing investigation and it’s really easy to understand why. My partner and i hear all about the dynamic ways you render priceless guidelines via the web site and as well as boost response from visitors about this article while our own simple princess is studying a lot of things. Take pleasure in the remaining portion of the year. You have been performing a fabulous job.
I have a 1967 chevelle with a munice 4 speed and console just finished the restoration and it looks beautiful it has a 496 bbc engine in it with a 800cfm carb an headers. I want to put a tko 5 speed transmission in, do I have to cut the trans tunnel to make the 5 speed fit or do you have a tko 5 speed that will fit I also have a gforce trans cross member. Any help you could give me would be great thank you Barbey Ivan Fisken
I could not refrain from commenting. Well written! Bibbie Langsdon Llovera
Yesterday, while I was at work, my sister stole my iPad and tested to see if it can survive a 30 foot drop, just so she can be a youtube sensation. My apple ipad is now broken and she has 83 views. I know this is totally off topic but I had to share it with someone!| Marcellina Alphard Alber
Well I definitely enjoyed studying it. This subject offered by you is very constructive for proper planning. Sashenka Horst Tiga
This article is genuinely a pleasant one it helps new web people, who are wishing for blogging. Fawnia Berky Klaus
I am also writing to let you be aware of what a beneficial encounter our daughter enjoyed reading through yuor web blog. She came to find some details, with the inclusion of how it is like to possess a marvelous teaching style to get many others effortlessly gain knowledge of chosen specialized subject areas. You really surpassed my expected results. Many thanks for presenting the great, dependable, educational and as well as fun guidance on that topic to Sandra.
Good day! I just wish to offer you a big thumbs up for your great information you have here on this post. I am coming back to your website for more soon. Belinda Tadeo Gayn
I want to express some appreciation to you for rescuing me from this type of scenario. Right after looking out through the world wide web and seeing strategies which were not pleasant, I was thinking my entire life was gone. Living without the presence of strategies to the problems you’ve solved as a result of your review is a serious case, as well as the ones that might have negatively affected my entire career if I hadn’t noticed your web blog. Your main competence and kindness in taking care of all the pieces was vital. I’m not sure what I would have done if I hadn’t discovered such a thing like this. I can at this moment relish my future. Thanks for your time so much for the high quality and effective guide. I will not hesitate to suggest your blog to anybody who wants and needs direction on this subject.
Neat blog! Is your theme custom made or did you download it from somewhere? A theme like yours with a few simple tweeks would really make my blog stand out. Please let me know where you got your design. Thanks| Margo Jan Monaco
I was able to find good advice from your articles. Tomasina Gabriel Odin
This is something that will need all of our combined efforts to address. Kara-Lynn Gunar Plossl
obviously like your web site however you need to take a look at the spelling on quite a few of your posts. Several of them are rife with spelling problems and I find it very troublesome to tell the reality nevertheless I will certainly come back again. Marcile Dewain Meghann
I would like to show my thanks to the writer just for bailing me out of this type of issue. After looking out throughout the search engines and finding suggestions that were not productive, I figured my entire life was gone. Living without the presence of answers to the difficulties you have sorted out by way of the guide is a serious case, as well as ones which might have in a wrong way damaged my entire career if I had not come across the blog. Your main capability and kindness in taking care of all the stuff was very helpful. I’m not sure what I would have done if I hadn’t come upon such a subject like this. I can also at this point relish my future. Thanks for your time so much for your specialized and result oriented guide. I will not be reluctant to refer the sites to any person who desires guide about this area.
I enjoy you because of all your effort on this site. Kim delights in going through research and it’s easy to see why. We notice all of the powerful manner you present reliable thoughts on the website and as well strongly encourage response from other people about this issue then my girl is always discovering a whole lot. Take pleasure in the rest of the new year. You are always conducting a fabulous job.
I precisely needed to thank you so much once more. I am not sure what I would’ve used in the absence of those advice shared by you relating to such subject. It had been a challenging case for me, however , coming across the specialised approach you managed the issue took me to jump for fulfillment. Now i’m happier for this help as well as believe you are aware of an amazing job you have been getting into training the rest using a site. I’m certain you have never come across all of us.
I simply had to thank you so much again. I’m not certain the things that I might have gone through without the type of creative concepts provided by you concerning that field. It has been a very challenging case in my view, but being able to see a specialized strategy you processed it took me to cry for fulfillment. Extremely happier for this advice and hope that you find out what a great job you were getting into teaching others through the use of your site. I’m certain you’ve never come across all of us.
I actually wanted to develop a quick remark to say thanks to you for the marvelous tips you are placing on this website. My particularly long internet investigation has finally been rewarded with incredibly good know-how to exchange with my contacts. I ‘d assert that we website visitors are definitely blessed to dwell in a good site with so many outstanding individuals with helpful solutions. I feel really blessed to have encountered your website and look forward to many more enjoyable moments reading here. Thank you once more for a lot of things.
I not to mention my pals ended up going through the nice suggestions on the website and then suddenly came up with a terrible suspicion I had not expressed respect to the web blog owner for those techniques. These ladies were definitely for that reason happy to read through all of them and already have extremely been tapping into them. Appreciation for actually being really thoughtful and then for using these kinds of outstanding subject matter millions of individuals are really desirous to discover. Our sincere regret for not saying thanks to you sooner.
I have to show thanks to the writer for bailing me out of this particular scenario. Right after searching through the the web and getting principles that were not beneficial, I believed my life was done. Existing minus the strategies to the difficulties you have fixed by way of your main review is a serious case, as well as the kind that could have badly affected my career if I hadn’t encountered the blog. Your own natural talent and kindness in playing with a lot of things was tremendous. I am not sure what I would have done if I hadn’t discovered such a point like this. It’s possible to now look ahead to my future. Thanks so much for the expert and sensible guide. I will not be reluctant to suggest your site to anybody who desires guidelines about this subject.
My wife and i ended up being now cheerful Emmanuel managed to deal with his investigations from the precious recommendations he obtained from your own web pages. It’s not at all simplistic to simply choose to be freely giving secrets and techniques which usually other folks could have been selling. And we also realize we have got the blog owner to appreciate for that. The type of illustrations you made, the simple blog menu, the relationships you can help foster – it’s mostly astonishing, and it’s making our son and us feel that the content is cool, which is pretty important. Thank you for the whole thing!
Today, I went to the beach with my children. I found a sea
shell and gave it to my 4 year old daughter and said “You can hear the ocean if you put this to your ear.” She
placed the shell to her ear and screamed. There was a hermit
crab inside and it pinched her ear. She never wants to go back!
LoL I know this is totally off topic but I had to tell someone!
Hi there all, here every one is sharing such knowledge, thus
it’s pleasant to read this website, and I used to pay a quick
visit this blog daily.
I am glad for writing to let you be aware of what a beneficial discovery my cousin’s daughter encountered studying your web site. She figured out numerous issues, including what it is like to have a marvelous teaching heart to make men and women really easily know precisely various problematic topics. You undoubtedly did more than her expectations. Thank you for churning out the good, safe, informative and in addition cool thoughts on the topic to Sandra.
Hey! Quick question that’s totally off topic. Do you know
how to make your site mobile friendly? My weblog looks weird when browsing from my iphone 4.
I’m trying to find a template or plugin that might be able
to correct this issue. If you have any recommendations, please share.
Many thanks!
I am only writing to let you know of the wonderful experience my wife’s child found going through your web site. She came to find lots of details, not to mention what it’s like to have a wonderful giving mindset to make other folks clearly gain knowledge of chosen specialized issues. You actually did more than my desires. Many thanks for delivering the great, healthy, revealing and in addition cool guidance on that topic to Mary.
Thanks for all of your work on this site. My mother loves conducting research and it’s really easy to see why. I hear all concerning the powerful means you deliver very helpful solutions by means of this web site and encourage contribution from some other people on this concept then my child is without a doubt learning a great deal. Have fun with the remaining portion of the new year. You are always doing a first class job.
Thanks so much for giving everyone an extraordinarily pleasant chance to read critical reviews from here. It is always so fantastic and also packed with a lot of fun for me personally and my office colleagues to search your site on the least thrice per week to read through the newest issues you have got. Of course, we are actually pleased considering the special points you serve. Selected 4 facts on this page are undeniably the most effective we have had.
I wanted to create you this very small note to be able to say thank you again on your nice principles you’ve featured on this site. This has been certainly surprisingly generous with people like you to provide extensively what exactly a number of us could possibly have marketed for an e book to make some cash on their own, especially considering that you could possibly have tried it if you considered necessary. Those tactics also acted like the easy way to understand that someone else have similar interest just as my very own to realize a lot more in respect of this matter. Certainly there are millions of more pleasant occasions up front for folks who read through your website.
I and my friends have been examining the excellent helpful tips from your web site and then unexpectedly I had an awful suspicion I had not expressed respect to you for those tips. All of the men were so passionate to see all of them and now have unquestionably been taking pleasure in these things. Appreciation for indeed being very considerate and for getting this form of terrific information most people are really wanting to be aware of. Our own sincere apologies for not expressing gratitude to earlier.
Needed to post you the tiny observation to finally say thanks a lot once again regarding the beautiful views you have documented on this site. It is particularly generous with people like you in giving publicly what exactly a few individuals could have offered for sale as an e book to make some money on their own, specifically considering the fact that you might well have done it in the event you wanted. These guidelines likewise worked as a fantastic way to be aware that someone else have a similar zeal similar to my personal own to see whole lot more on the subject of this matter. I believe there are several more enjoyable periods in the future for those who scan through your blog post.
Thanks a lot for providing individuals with an extraordinarily spectacular possiblity to check tips from this blog. It’s always so nice and also stuffed with a great time for me personally and my office co-workers to search your site at the least 3 times a week to learn the fresh guidance you have. And lastly, I am actually pleased concerning the impressive tips you give. Some 4 facts in this post are in reality the most impressive we have all ever had.
I’m writing to let you know what a perfect discovery my wife’s princess enjoyed going through the blog. She figured out a good number of issues, not to mention what it’s like to have an ideal teaching mood to make other folks really easily thoroughly grasp a variety of complex subject areas. You undoubtedly surpassed visitors’ expected results. Thanks for providing such necessary, healthy, educational not to mention easy guidance on this topic to Mary.
I wish to convey my passion for your generosity for folks who should have help on this subject. Your special commitment to getting the solution throughout appeared to be pretty advantageous and has specifically permitted those much like me to realize their aims. This warm and friendly help implies much to me and much more to my peers. Thanks a ton; from each one of us.
I happen to be commenting to make you be aware of of the impressive discovery my cousin’s daughter enjoyed viewing your web page. She learned a lot of pieces, which include what it is like to have a marvelous helping style to make many people without problems thoroughly grasp specific specialized subject areas. You actually surpassed my desires. I appreciate you for delivering the effective, healthy, explanatory and even fun tips about the topic to Evelyn.
I want to express some appreciation to you for bailing me out of this particular condition. As a result of looking through the world wide web and meeting advice which are not productive, I was thinking my entire life was well over. Existing minus the answers to the issues you’ve sorted out as a result of your entire guideline is a crucial case, and the ones which may have in a negative way affected my career if I had not noticed your blog post. Your main understanding and kindness in touching all the pieces was very useful. I don’t know what I would have done if I hadn’t encountered such a point like this. I am able to at this moment look ahead to my future. Thanks so much for this expert and effective guide. I won’t be reluctant to endorse your blog to anybody who needs and wants recommendations about this problem.
My spouse and i have been so joyful that Louis could finish off his analysis from the ideas he made from your very own web pages. It is now and again perplexing to just choose to be making a gift of instructions which often the others could have been trying to sell. And we see we now have the writer to be grateful to for that. The specific illustrations you made, the simple site navigation, the relationships you give support to instill – it’s everything spectacular, and it’s facilitating our son and us understand the subject is exciting, and that is highly vital. Thank you for everything!
My wife and i got contented that Albert managed to carry out his inquiry from the ideas he had when using the blog. It’s not at all simplistic just to always be handing out hints that many people today may have been making money from. And we already know we’ve got the writer to thank because of that. The type of illustrations you have made, the easy website navigation, the relationships you make it possible to foster – it is all terrific, and it is facilitating our son and us believe that this theme is exciting, which is very pressing. Many thanks for all!
I not to mention my friends appeared to be going through the excellent guidelines on the blog then unexpectedly developed a horrible suspicion I had not expressed respect to the website owner for those techniques. All of the people became absolutely warmed to learn them and already have very much been tapping into them. Thanks for actually being simply accommodating as well as for picking such useful subject matter most people are really eager to discover. Our sincere apologies for not expressing appreciation to you sooner.
A lot of thanks for your whole labor on this blog. My niece loves working on research and it’s really obvious why. I learn all about the lively ways you produce powerful tricks via your website and as well improve contribution from some other people on that matter plus our princess is truly understanding a lot of things. Take advantage of the rest of the year. You are always doing a tremendous job.
My spouse and i have been peaceful Chris could complete his preliminary research through your ideas he had when using the web site. It is now and again perplexing to simply always be freely giving ideas that many some others have been selling. And now we remember we need the writer to be grateful to for that. All the illustrations you’ve made, the simple web site navigation, the friendships you can aid to instill – it’s mostly remarkable, and it is making our son in addition to the family consider that this situation is enjoyable, which is rather essential. Thank you for everything!
I must express some appreciation to you for bailing me out of such a challenge. Because of browsing through the world-wide-web and coming across opinions which were not helpful, I was thinking my life was over. Existing minus the solutions to the issues you’ve solved by way of this review is a serious case, and the ones that might have negatively affected my career if I had not come across the website. Your good competence and kindness in controlling the whole thing was excellent. I don’t know what I would have done if I had not come upon such a solution like this. I can also now look forward to my future. Thanks very much for this impressive and amazing help. I will not hesitate to refer your site to anyone who needs counselling on this area.
I simply needed to appreciate you again. I’m not certain what I could possibly have sorted out in the absence of those hints revealed by you about such a theme. It was before an absolute frustrating dilemma for me, but spending time with this specialized fashion you treated the issue made me to jump for contentment. Now i am happier for the work and in addition sincerely hope you are aware of a great job you are always getting into teaching men and women with the aid of your web page. I am certain you haven’t encountered any of us.
I wish to point out my affection for your kindness giving support to men and women that should have assistance with this important niche. Your very own commitment to passing the solution along became surprisingly important and have really enabled people like me to attain their pursuits. The useful advice indicates this much a person like me and much more to my mates. Thank you; from everyone of us.
Hmm is anyone else having problems with the images on this blog
loading? I’m trying to find out if its a problem on my end or
if it’s the blog. Any feed-back would be greatly appreciated.
Your point of view caught my eye and was very interesting. Thanks. I have a question for you.
Teachers become mentors, helping students develop the skills necessary for self-directed, lifelong learning.
Can you be more specific about the content of your article? After reading it, I still have some doubts. Hope you can help me.
Thank you for your sharing. I am worried that I lack creative ideas. It is your article that makes me full of hope. Thank you. But, I have a question, can you help me?
Your article helped me a lot, is there any more related content? Thanks!