-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinheri.cpp
More file actions
47 lines (43 loc) · 775 Bytes
/
inheri.cpp
File metadata and controls
47 lines (43 loc) · 775 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include<iostream>
using namespace std;
class A {
int m;
public :
void getdata_m(void);
int retuM(void);
};
class B : public A{
int n ,sum;
public:
void getdata_n(void);
int add(void);
void display();
};
void A :: getdata_m(){
cout<<"Enter value of m : ";
cin>>m;
}
int A :: retuM(){
return (m);
}
void B ::getdata_n(){
cout<<"Enter value of n : ";
cin>>n;
}
int B :: add(){
sum = retuM() + n; //here we cannot write direct m bcz m is private
return (sum);
}
void B :: display(){
cout<<"Value of m is "<<retuM()<<endl;
cout<<"Value of n is "<<n<<endl;
cout<<"Sum "<<sum<<endl;
}
int main(){
B num;
num.getdata_m();
num.getdata_n();
num.add();
num.display();
return 0;
}