-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclass17.cpp
More file actions
56 lines (50 loc) · 987 Bytes
/
Copy pathclass17.cpp
File metadata and controls
56 lines (50 loc) · 987 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
55
56
//Inheritance
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
using namespace std;
//this is main class called parent class
class First
{
private:
int a;
protected: //this is access specifier // not accessible with object of class First
void setValue(int x)
{
a = x;
}
int getData()
{
return a;
}
};
//this is inherited class called child class
class Second:public First //inherite of class First
{
private:
int b;
public:
//setting value in First class
void setData(int a)
{
setValue(a);
}
//showing data after getting from class First
void showData()
{
b = getData();
cout<<"value is "<<b<<endl;
}
};
int main(int argc, char const *argv[])
{
int temp;
system("cls");
Second sobj; //creating object
cout<<"Enter number ";
cin>>temp;
sobj.setData(temp);
sobj.showData();
system("pause");
return 0;
}