Polymorphism and Inheritance
Polymorphism
1. Function Overloading
// oop_p3_1.cpp
#include <iostream>
using namespace std;
class function_overlasding
{
public:
// function with 1 int parameter
int func(int x) {
return x + 5;
}
// function with same name but 1 double parameter
void func(double x) {
cout << "value of x is " << x << endl;
}
// function with same name and 2 int parameters
void func(int x, double y) {
cout << "value of x and y is " << x << ", " << y << endl;
}
};
int main() {
function_overlasding obj1;
// Which function is called will depend on the parameters passed
// The first 'func' is called
int a = obj1.func(7);
cout << a << endl;
// The second 'func' is called
obj1.func(9.132);
// The third 'func' is called
obj1.func(85,9.132);
return 0;
} 2. Operator Overloading
Inheritance

1. Single Inheritance

2. Multiple Inheritance

3. Multilevel Inheritance

Access Specifiers for Inheritance
Last updated
Was this helpful?