Skip to content

Commit 4e27545

Browse files
committed
cpp course
1 parent 663e1ef commit 4e27545

File tree

2 files changed

+80
-0
lines changed

2 files changed

+80
-0
lines changed

tut18.cpp

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#include <iostream>
2+
using namespace std;
3+
4+
int count=1;
5+
class Employee {
6+
public:
7+
Employee(){
8+
count++;
9+
cout << "Constructor called" << endl;
10+
cout << count << endl;
11+
};
12+
~Employee(){ // <-- Destructor called here
13+
count--;
14+
cout << "Destructor called" << endl;
15+
cout << count << endl;
16+
}
17+
};
18+
19+
int main(){
20+
Employee a;
21+
{
22+
cout << "Entering here" << endl;
23+
Employee b, c; // <-- constructor will be called here
24+
cout << "Exiting here" << endl;
25+
}; // <-- here destructor will be called , because b and c ended here as the object ends
26+
return 0;
27+
}

tut19.cpp

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#include <iostream>
2+
using namespace std;
3+
4+
class Employee;
5+
6+
// BASIC INHERITANCE
7+
8+
class Employee
9+
{
10+
int id;
11+
12+
public:
13+
int salary;
14+
Employee(int v1)
15+
{
16+
id = v1;
17+
salary = 34;
18+
}
19+
Employee() {}
20+
void show(void)
21+
{
22+
cout << id << endl;
23+
cout << "Hello Employee!!" << endl;
24+
}
25+
};
26+
27+
class Programmer : public Employee // <-- private of Employee will never come here and by default every thing comes from Employee as private and to make public of Employee , write public here for Employee
28+
{
29+
int coder;
30+
31+
public:
32+
Programmer(int v1)
33+
{
34+
coder = v1;
35+
};
36+
void show(void)
37+
{
38+
cout << coder << endl;
39+
cout << "Hello Programmer!!" << endl;
40+
}
41+
};
42+
43+
int main()
44+
{
45+
Employee a(2);
46+
a.show();
47+
48+
Programmer ankit(1);
49+
ankit.show();
50+
cout << ankit.salary;
51+
52+
return 0;
53+
}

0 commit comments

Comments
 (0)