-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpolymorphism.cpp
More file actions
60 lines (49 loc) · 1014 Bytes
/
polymorphism.cpp
File metadata and controls
60 lines (49 loc) · 1014 Bytes
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
#include <iostream>
using namespace std;
// compile time polymorphism
class Maths
{
public:
// function overloading
void sayHello()
{
cout << "Hello , I am a Rahul" << endl;
}
void sayHello(string fname, string lname)
{
cout << "Hello , I am a " << fname << lname << endl;
}
void sayHello(string name)
{
cout << "Hello , I am a " << name << endl;
}
};
class B{
public:
//operator overloading
int a , b;
void operator + (B &obj){
int val1 = this->a;
int val2 = obj.a;
cout << "Output is :- " << val2 - val1 << endl;
}
void operator() ()
{
cout << "I am Bracket with value is :- " << this->a << endl;
}
};
int main()
{
Maths m1;
m1.sayHello();
m1.sayHello("Rohan", "Avhad");
m1.sayHello("Harshal");
B obj1 , obj2;
obj1.a = 4;
obj2.a = 7;
//current obj + input parameter obj
obj1 + obj2;
// () operator overloading
obj1();
obj2();
}