- Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path20)OOPS_Inheritance.cpp
32 lines (27 loc) · 790 Bytes
/
20)OOPS_Inheritance.cpp
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
#include<iostream>
usingnamespacestd;
classEmployee// Class
{
public:
string name;
int salary;
voidprintDetails() // Method
{
cout << "Name of our first employee is " << this->name << endl;
cout << "Salary of our first employee is " << this->salary << endl;
}
};
classEngineer : publicEmployee// Child Class
{
public:
string task = "Program Software";
};
intmain()
{
Engineer engineer1; // Object of child class
engineer1.name = "Mooazam"; // Setting values in parent class
engineer1.salary = 100000; // Setting values in parent class
engineer1.printDetails(); // Accessing parent class
cout << "Task of our first employee is to " << engineer1.task << endl;
return0;
}