O'Reilly logo

C# Primer Plus by Klaus Michelsen

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required