-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path34Inheritance_SyntaxandVisibility.cpp
More file actions
57 lines (49 loc) · 1.2 KB
/
34Inheritance_SyntaxandVisibility.cpp
File metadata and controls
57 lines (49 loc) · 1.2 KB
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
#include <iostream>
using namespace std;
//This is Base Class
class Employee
{
public:
int id;
float salary;
Employee(){};
Employee(int inpID)
{
id = inpID;
salary = 34;
}
};
//Derived Class
/*class {{derived-class-name}} : {{visibility-mode}} {{base-class-name}}{
class members/methods/etc...
}*/
/*
1.) Default visibility mode is private
2.) Public visibility mode: Public members of the base class becomes Public members of the derived class
3.) Private visibility mode: Public members of the base class becomes private members of the derived class
4,) Private members of Base class can never be Inherited
*/
//Creating a Programmer class derived from Employee base class
class programmer : public Employee // without using public we cannot access id, and cannot use XYZ.id
{
public:
programmer(int Inpid)
{
id = Inpid;
};
int languageCode = 9;
void getdata(){
cout<<id<<endl;
}
};
int main()
{
Employee Harshit(1), Vanshika(2);
cout << Harshit.salary << endl;
cout << Vanshika.salary << endl;
programmer skillF(1);
cout << skillF.languageCode<<endl;
skillF.getdata();
cout<<skillF.id<<endl;
return 0;
}