Function Overriding C++

Polymorphism in C++

Polymorphism means having multiple forms of one thing. We can achieve the polymorphism by function overriding. The function overriding occurs when both parent and child class have the member function with the same declaration.

The member function with the same declaration means to have the function with the same name, same return type, and same parameters.

Requirements of Function Overriding

  1. We must Inherit the classes.
  2. Function overriding cannot be done within the same class.
  3. Function overriding occurs when at least one derived class and one base class must be there.
  4. The function that is being redefined must have the exact same declaration/signatures in both parent and child classes. As discussed earlier that they must have the same name, same return type, and the same parameter list.

Function Overriding C++

Output

Derived Class function is invoked.

Video Lecture