2. Function over-loading
• Multiple functions with same name and different parameters.
void add(int a, int b) void add(int a, int b, int c)
• Over-loading is example of static polymorphism.
• can’t be overloaded if they differ only in return type.
• Functions differs in one of following ways.
No of parameters.
Type of parameters.
Sequence of parameters.
3. • Valid example
a) Sum(int num1, int num2, int num3)
Sum(double num1, int num2)
• Invalid example
a) Int sum (int ,int)
double sum(int, int)
• Not valid though they have different return types
5. Method over-ridng
• Member function in derived class with same name as in parent class.
• Member function in derived class have same signatures as in parent
class.
• Same function name in child as well as base class.
• If you create an object of the derived class and call the member
function which exists in both classes.
• the member function of the derived class is invoked and the function
of the base class is ignored.
• can’t done within one class.
6. Access to overridden function
• To access the overridden function of the base class from the derived
class, scope resolution operator :: is used.
• In function of derived class use scope resolution operator as shown
below.
• example:
base class::function name()
base class::display();
7. Method over-riding
• it is not possible to remove or restrict functionality from a base class
other than by modifying the source code.
• However, in a derived class, it is possible to hide functionality that
exists in the base class
• This can be done simply by changing the relevant access specifier.