Hiding vs. Overriding a Method
Explore how to differentiate between hiding and overriding methods in C#. Understand when to use the new keyword to hide base class methods and how overriding virtual methods enables polymorphic behavior at runtime. This lesson helps you apply these concepts to manage inheritance and method execution in your C# programs.
We'll cover the following...
Hide
Hiding creates a method of the same name and signature as it it’s defined in the base class. To hide a method, we use the new keyword:
public new void Voice()
{
}
Instead of providing a method with a different implementation (overriding), the new keyword creates an entirely different method, but with the same name and signature. A method marked with the new keyword isn’t associated by any means with the base version of the method. They’re completely separate entities.