final Member Functions
We have delayed explaining
final member functions until this chapter to keep the earlier chapters shorter.
final member functions are relevant only for classes and interfaces because structs do not support inheritance.
final specifies that a member function cannot be redefined by a subclass. In a sense, the implementation that this class or interface provides is the final implementation of that function. An example of a case where this feature is useful is where the general steps of an algorithm are defined by an interface and the finer details are left to subclasses.
Let’s see an example of this with a
Game interface. The general steps of playing a game is being determined by the
play() function of the following interface: