-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinheritance.cpp
More file actions
43 lines (36 loc) · 777 Bytes
/
inheritance.cpp
File metadata and controls
43 lines (36 loc) · 777 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
#include <iostream>
#include <string>
using namespace std;
class Teacher { // Parent class
public:
string name;
int age;
void getinfo() {
cout << "Name: " << name << endl;
cout << "Age: " << age << endl;
}
};
class Student : public Teacher { // child class
public:
int roll_no;
void getinfo() {
cout << "Name: " << name << endl;
cout << "Age: " << age << endl;
cout << "Roll No: " << roll_no << endl;
}
};
int main() {
Student s1;
s1.age = 20;
s1.name = "Furqan";
s1.roll_no = 4218;
s1.getinfo();
return 0;
}
/*
Type of Inheritance
a) Single Inheritance
b) Multi Level Inheritance
c) Multiply Inheritance
d) Hierarchial Inheritance
*/