-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path03-Inheritance
130 lines (104 loc) · 1.76 KB
/
03-Inheritance
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
Types of Inheritance
> Single Inehritance
> Mulitlevel Inheritance
> Multiple Inheritance
> Hierachical Inheritance
> Hybrid Inheritance
It means Inherite the other class function to the other function classs
/* Single Inheritance */
class A
{
};
class B:public A
{
};
/* Multi level Inheritance */
class A
{
};
class B:public A
{
};
class C:public B
{
};
/* Multiple Inheritance */
class A1
{
};
class A2
{
};
class B:public A1,public A2
{
};
/* Hierarchical Inheritance */
/* having one parent class and two other class conected with that */
class A
{
};
class B1:public A
{
};
class B2:public A
{
};
/*.............................................Important Concept ....................*/
> VISITBILITY MODE IN INHERITANCE
If the class has three type of data
class A
{
public:
int x;
private :
int y;
protected :
int z;
}
and we have one more class by using which we have to inherit the class A
# We have available all the data but we can't access all the data
# We can access the only protected and public data
class B: private A
{
protected and public data both become private
}
class B: protected A
{
protected and public data both become protected
}
class B: public A
{
protected data are still protected
and public data are still public
}
/*................................................................................*/
#include <bits/stdc++.h>
using namespace std;
class Student
{
int id;
string s1;
public:
void give();
};
void Student::give()
{
id =2;
s1 = "Ankit"
cout << id << " " << s1 << endl;
}
class Teacher:public Student,public ForMoreClass-Write Like this
{
public:
int ind1;
void solve()
{
cout<<"INherit"<<endl;
}
};
// By this method we can use the other class variable
int main()
{
Teacher t1;
cout<<t1.s1<<endl;
}