C++ Function Overriding
When the base and derive class both contain the same function name and calling the function through derived object invokes derived class function called
function overriding. Function overloading is achieved in inheritance.
C++ Function Overriding Example
#include <iostream>
using namespace std;
class Vehicle
{
private:
int speed;
public:
void running(){
cout<<"Vehicle runs"<<endl;
}
};
class Bike: public Vehicle{
public:
void running(){
cout<<"Bike runs"<<endl;
}
};
int main()
{
Bike bike;
bike.running();
return 0;
}
Output: