In the Inheritance for reference types only section we saw how we can use inheritance with classes to inherit and override functionality defined in a super class. You may be wondering how and when the appropriate implementation is chosen. The process of choosing which implementation to call is performed at runtime and is known as dynamic dispatch.
One of the key points to understand from the last paragraph is that the implementation is chosen at runtime. What that means is that a certain amount of runtime overhead is associated with using class inheritance as shown in the Inheritance for reference types only section. For most applications, this overhead is not a concern; however, for performance-sensitive applications such as games this overhead can be costly.
One of the ways that we can reduce the overhead associated with dynamic dispatch is to use the final
keyword. The final
keyword puts a restriction on the class, method, or function that indicates that it cannot be overridden...