-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclass26.cpp
More file actions
54 lines (51 loc) · 746 Bytes
/
class26.cpp
File metadata and controls
54 lines (51 loc) · 746 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
48
49
50
51
52
53
54
#include<iostream> //inheritance
using namespace std;
class base{
protected:
int x;
public:
base()
{
cout<<"Base class constrictor";
x=0;
}
void plus()
{
x++;
}
void showbase()
{
cout<<"\n\nx="<<x<<endl;
}
};
class derv : public base
{
private:
int y;
public:
derv():base()
{
cout<<"DERIVED CLASS CONSTRUCTOR\n";
y=0;
}
void minus()
{
x--;
y--;
}
void showderv()
{
cout<<"\n\ny = "<<y<<endl;
}
};
int main()
{
derv obj;
obj.plus(); //x++
obj.plus();//x++
obj.plus();//x++
obj.minus();//x++ and y--
obj.showbase();
obj.showderv();
return 0;
}