Method overriding occurs when a subclass has a definition of one of the member functions of the superclass. That base function is said to be overridden.
* The superclass method can be invoked followed by the scope resolution operator.
* A virtual method that is declared final in the superclass cannot be overridden.
* A method can be declared override to make the compiler check that it overrides a method in the superclass.
```
#include <iostream>
using namespace std;
class Super
{
public:
virtual void print() { cout<<"Super::print"<<endl; }
void show() { cout<<"Super::show"<<endl; }
virtual void run() final { cout<<"Super::run"<<endl; }
};
class Sub:public Super
{
public:
void print() override { cout<<"Sub::print"<<endl; }
void show() { cout<<"Sub::show"<<endl; }
};
int main()
{
Sub sub;
Super *super = ⊂
super->Super::print(); // Super::print
super->print(); // Sub::print
super->show(); // Super::show
return 0;
}
```