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
- We must Inherit the classes.
- Function overriding cannot be done within the same class.
- Function overriding occurs when at least one derived class and one base class must be there.
- The function that is being redefined must have the exact same declaration in both parent and child class. As discussed earlier that they must have the same name, same return type, and the same parameter list.
using namespace std;
cout << "Base class";
class Derived:public Base
cout << "Derived Class function is invoked.";
Derived Class function is invoked.
- Why do we need various number systems in computer science? - April 16, 2021
- 5 Best Places to Study Engineering - March 19, 2021
- How Students Can Pick a Good Custom-Paper Writing Service? - March 5, 2021