-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path33_oops.cpp
More file actions
46 lines (41 loc) · 1.5 KB
/
33_oops.cpp
File metadata and controls
46 lines (41 loc) · 1.5 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
//polymorphism in c++ is two type
// -one name and multiple forms
// - eg function overloading, operator overloading, virctual overloading
// polymorphism
// 1. compile time polymorphism
// 1.1 function overloading
// 1.2 operator overloading
// 2. Run time polymorphism
// 2.1 virctual overloading
#include<iostream>
using namespace std;
class Baseclass{
public:
int var_base;
void display(){
cout<<"1.Dispalying base class variable var_base"<<" "<<var_base<<endl;
}
};
class Derivedclass: public Baseclass{
public:
int var_derived;
void display(){
cout<<"2.Dispalying base class variable var_base"<<" "<<var_base<<endl;
cout<<"2.Dispalying derived class variable var_base"<<" "<<var_derived<<endl;
}
};
int main(){
Baseclass* base_class_pointer; //(name of pointer -> base_class_pointer)
Baseclass obj_base; //(object of class Baseclass -> obj_class )
Derivedclass obj_derived; ////(object of class Derivedclass: -> obj_class )
base_class_pointer = &obj_derived; //pointing base class pointer to derived class pointer
base_class_pointer->var_base=34;
// base_class_pointer->var_derived=134; will through error
base_class_pointer->display();
Derivedclass* derived_class_pointer;
derived_class_pointer=&obj_derived;
derived_class_pointer->var_base=13;
derived_class_pointer->var_derived=1340;
derived_class_pointer->display();
return 0;
}