Home | | Object Oriented Programming and Data Structures | Multiple inheritances with suitable c++ coding

Chapter: Object Oriented Programming and Data Structure : Inheritance and Polymorphism

Multiple inheritances with suitable c++ coding

Inheritance is a mechanism of deriving a new class from a old class.

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();

 

}


Study Material, Lecturing Notes, Assignment, Reference, Wiki description explanation, brief detail
Object Oriented Programming and Data Structure : Inheritance and Polymorphism : Multiple inheritances with suitable c++ coding |


Privacy Policy, Terms and Conditions, DMCA Policy and Compliant

Copyright © 2018-2023 BrainKart.com; All Rights Reserved. Developed by Therithal info, Chennai.