Overriding Functions
Overriding Functions
Programming Techniques
Overriding Functions
• Two classes to have a function with the same name.
• Function overriding is accomplished by using inheritance and virtual
functions.
• The concept through which we define a function in parent class and
the child class with the same return type and parameters is known as
function overriding.
• It is achieved during runtime.
Problem
Problem
Output
Output
Overriding Functions Vs Overloading
Function
Function Overloading Function Overriding
• Function Overloading provides multiple • Function Overriding is the redefinition
definitions of the function of base class function in its derived
• An example of compile time. class
• Overloaded functions are in same • An example of run time.
scope. • Overridden functions are in different
• Overloading is used when the same scopes.
function has to behave differently • Overriding is needed when derived
depending upon parameters passed to class function has to do some different
them. job than the base class function.
• A function has the ability to load • A function can be overridden only a
multiple times. single time.
• In function overloading, we don’t need • In function overriding, we need an
inheritance. inheritance concept.
Virtual Constructor
The creation of a virtual constructor is not possible because: