Function Overriding in c++

Card image cap

Overriding ?

Function overriding is a feature that allows us to have a same function in child class which is already present in the parent class.


It provides multiple definitions of the function by changing signature i.e changing number of parameters, change datatype of parameters, return type doesn’t play anyrole

It is used to achieve runtime polymorphism. It enables you to provide specific implementation of the function which is already provided by its base class.

Inheritance allows software developers to derive a new class from the existing class. The derived class inherits features of the base class (existing class).

If we inherit a class into the derived class and provide a definition for one of the base class's function again inside the derived class, then that function is said to be overridden, and this mechanism is called Function Overriding.


Card image cap

Example 1:



Output :

 Function of Child Class
Card image cap

Example 2:



Output :

This is Display() method of DerivedClass
This is Show() method of BaseClass
Card image cap