OOPS Notes Unit-6
OOPS Notes Unit-6
Credits: 4
• Polymorphism is the ability of any data to be processed in more than one form.
• The word itself indicates the meaning as poly means “many” and morphism
means “types”
• So, the same person has to have many features but has to implement each as
per the situation and the condition. Also called as static polymorphism
Polymorphism >> Types
Polymorphism >> Functional Overloading
Function Overloading
• When there are multiple functions with the same name but different parameters, then the functions are said to
be overloaded, hence this is known as Function Overloading.
• Functions can be overloaded by changing the number of arguments or/and changing the type of arguments.
In simple terms, it is a feature of object-oriented programming providing many
• There are certain Rules of Function Overloading that should be followed while overloading a function.
Polymorphism >> Functional Overloading
•Parameters should have a different type •Parameters should have a different number
#include <iostream>
#include <iostream> using namespace std;
using namespace std;
void add(int a, int b)
{
void add(int a, int b)
cout << "sum = " << (a + b);
{
}
cout << "sum = " << (a + b);
}
void add(int a, int b, int c)
void add(double a, double b)
{
{
cout << endl << "sum = " << (a + b + c);
cout << endl << "sum = " << (a + b);
}
}
// Driver code
int main()
int main()
{
{
add(10, 2);
add(10, 2);
add(5.3, 6.2);
add(5, 6, 4);
return 0;
return 0;
}
}
Polymorphism >> Functional Overloading
#include<iostream>
using namespace std;
return 0;
}
Polymorphism >> Functional Overloading
1. sizeof Operator
This returns the size of the object or datatype entered as the operand. This is evaluated by the compiler and
cannot be evaluated during runtime. The proper incrementing of a pointer in an array of objects relies on the
sizeof operator implicitly. Altering its meaning using overloading would cause a fundamental part of the
language to collapse.
A function is a block of statements that together performs a specific task by taking some input and producing a
particular output. Function overriding in C++ is termed as the redefinition of base class function in its derived class
with the same signature i.e. return type and parameters. It falls under the category of Runtime Polymorphism.
Function overriding:
Method overriding is a feature that allows you to redefine the parent class method in the child class based on its
requirement. In other words, whatever methods the parent class has by default are available in the child class.
But, sometimes, a child class may not be satisfied with parent class method implementation. The child class is
allowed to redefine that method based on its requirement. This process is called method overriding.