You can mark it virtual
to indicate that it is 'virtual' in the class you are inheriting from (even though you don't have to do this), and mark it final
to indicate that no class deriving from your class may override it further. This may happen when you are implementing an abstract base class, for example. This is C++11, so it's not useful; override
is a much better indication, since it is enforced by the compiler.
Another possibility: you want this method not to be overridden, but you want to be able to change that without recompilation. Remember that virtual
means it is in the virtual table. even if the compiler will not let you override it.
I think the purpose of the example you have shown is to demonstrate priorities between virtual
and final, and nothing more. It is a minimal use of final
, not a useful one.
Marking a non-virtual method as final
makes no sense, since you cannot override them anyway. If you want the compiler to prevent hiding, that is a completely different issue, that has nothing to do with the method being final
. In a sense, non-virtual methods are final already, but hidable.