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

Multiply two numbers in Java using scanner| 5 different ways

Multiply two numbers in Java using scanner| 5 different ways In this article, we will…

9 months ago

5 different ways to Divide two numbers in Java using scanner

5 Different ways to Divide two numbers in Java using scanner In this article, we…

10 months ago

Learn 8 Ways to Subtract Two Numbers Using Methods in Java

Learn 8 Ways to Subtract Two Numbers Using Methods in Java In this article, we…

10 months ago

10 ways to subtract two numbers in Java

10 ways to subtract two numbers in Java In this article, we will discuss the…

10 months ago

Java Code Examples – Multiply Two Numbers in 5 Easy Ways

Java Code Examples – Multiply Two Numbers in 5 Easy Ways In this article, we…

10 months ago

How to Divide two numbers in Java| 5 different ways

How to Divide two numbers in Java| 5 different ways In this article, we will…

10 months ago

This website uses cookies.