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
Multiply two numbers in Java using scanner| 5 different ways In this article, we will…
5 Different ways to Divide two numbers in Java using scanner In this article, we…
Learn 8 Ways to Subtract Two Numbers Using Methods in Java In this article, we…
10 ways to subtract two numbers in Java In this article, we will discuss the…
Java Code Examples – Multiply Two Numbers in 5 Easy Ways In this article, we…
How to Divide two numbers in Java| 5 different ways In this article, we will…
This website uses cookies.