Explain multiple inheritances with suitable c++
coding.
INHERITANCE:
• Inheritance
is a mechanism of deriving a new class from a old class.
• It
provides the concept of reusability
• By
inheritance some or all the properties of a class can be derived in to another
class.
• The class
which provides the properties is called as base class and the class which
derives the properties is called as derived class.
Multiple inheritance:
It is a
type of inheritance in which a class can inherit properties from more than one
class.
Syntax:
Class
derivedclass name : visibility mode baseclass1,visibilitmode baseclass2
{
body of
the derived class; };
visibility
mode can be either private or public.
Example :
#include
#include
class bc1
{
protected:
int a;
public :
void
get()
{
cout
<<”\n enter the value for a\n”;
cin
>>a;
}
};
class bc2
{
protected:
int b;
public;
void get1()
{
cout
<<” \n enter the value for b \n”;
cin>>b;
}
};
class dc
: public bc1, public bc2
{
public :
void show()
{
cout
<<”The values of a and b are” ;
cout
<<<”\n”<
}
};
void
main()
{
clrscr();
dc d;
d.get();
d.get1();
d.show();
}
Related Topics
Privacy Policy, Terms and Conditions, DMCA Policy and Compliant
Copyright © 2018-2023 BrainKart.com; All Rights Reserved. Developed by Therithal info, Chennai.