Method hiding

Even if a function member (here referring to a method, property or indexer) is not declared virtual in a base class you can still write a function with the same signature and return type in its derived class. However, the dynamic binding mechanism will never be activated for this function. Consequently if you call a non-virtual function for a variable of a base class which references an object of the derived type it will invoke the version implemented in the base class not the version implemented in the derived class (as had been the case if the function was declared virtual). Instead of overriding the non-virtual base class function the new function is said to hide the base class function. Listing 17.9 demonstrates the difference ...

Get C# Primer Plus now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.