-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path26_oops.cpp
More file actions
61 lines (58 loc) · 1.31 KB
/
26_oops.cpp
File metadata and controls
61 lines (58 loc) · 1.31 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
58
59
60
61
#include<iostream>
using namespace std;
/*
case1:
class B: public A (class B inheritance from class A) {
//order of excution of constructor --> first A()then B()
};
case2:
class A: public B {
//order of excution of constructor --> first B()then A()
};
case3:
class A: public B,virtual public C{
//order of excution of constructor --> first c()then B() and A
};
*/
class Base1{
int data1;
public:
Base1(int i){ //constructor
data1 = i;
cout<<"Base1 class constructor called"<<endl;
}
void print1(void){
cout<<"the value of data1 is" <<" "<<data1<<endl;
}
};
class Base2{
int data2;
public:
Base2(int i){
data2 = i;
cout<<"Base2 class constructor called"<<endl;
}
void print2(void){
cout<<"the value of data2 is" <<" "<<data2<<endl;
}
};
class Derived: public Base1, public Base2{ //derived class inheritance
int derived1,derived2;
public:
Derived(int a, int b, int c, int d): Base1(a),Base2(b){
derived1=c;
derived2=d;
cout<<"the derived class constructor called"<<endl;
}
void printd(void){
cout<<"the value of derived1"<<" "<<derived1<<endl;
cout<<"the value of derived2"<<" "<<derived2<<endl;
}
};
int main(){
Derived khushi(1,2,3,4);
khushi.print1();
khushi.print2();
khushi.printd();
return 0;
}