Categories: C++Learn C++

Multiple inheritance in C++ language

Multiple inheritances in C++ language

In this tutorial, we will discuss the OOP concept of multiple inheritances in C++ language.
Inheritance is the process of inheriting data members and methods of one class by another class. When a class is derived from two or more base class, it is called multiple inheritance. Multiple inheritance is a feature of the object-oriented programming language of C++.
In C++, a child class can inherit from more than one parent class. Multiple inheritance is not support in Java.

Syntex

 

Ex

class A

{

””””””””””””””””

};

class B{

………………………

}

class C access_specifier A, acces_Specifier B//inherit properties from classes A and B



Program 1

Explanation is above program

#include <iostream>
using namespace std;
class cost //start of class cost
{
protected://access modifier – protected
int cp;
public://access modifier – public
void getcp()
{
cout << “Enter the cost prize:” << endl;
cin >>cp;
}
}; //end of class cost
class sell
{  //start of class sell
protected:  //access modifier – protected
int sp;
public:
void getsp()
{
cout << “Enter the selling prize:” << endl;
cin >>sp;
}
};  //end of class sell

class profit:cost,sell
//start of class profit and which is inherits property from parant class cost, sell
private:    //access modifier – private
int pf;
public:  //access modifier – public
void profits()
{
getcp();
getsp();
pf=sp-cp;
cout << “profit is:” <<pf<<endl;
cin >>sp;
}
}; //end of class profit
int main()
{
profit o; //create object for class profit
o.profits();  //call method profit through object
return 0;
}

 

Similar post

Inheritance in Java                 Inheritance in C++        Interface in Java
   
Karmehavannan

Recent Posts

Subtract two numbers using method overriding

Subtract two numbers using method overriding   Program 1

3 months ago

PHP Star triangle Pattern program

PHP Star triangle Pattern program Here's a simple Java program that demonstrates how to print…

3 months ago

Using function or method to Write temperature conversion : Fahrenheit into Celsius

Using Function or Method to Write to temperature conversion: Fahrenheit into Celsius In this article,…

1 year ago

Function or method:temperature conversion from Fahrenheit into Celsius – Entered by user

Function or method of temperature conversion from Fahrenheit into Celsius In this article, we will…

1 year ago

Write temperature conversion program: Fahrenheit into Celsius

Write temperature conversion program: from Fahrenheit to Celsius In this article, we will discuss the…

1 year ago

How to write a program to convert Fahrenheit into Celsius

How to write a program to convert Fahrenheit into Celsius In this article, we will…

1 year ago

This website uses cookies.