I have a problem with terminology. According to MSDN: "The override modifier extends the base class method, and the new modifier hides it." However, in the following example:
using System;
namespace ConsoleApplication2
{
class BaseClass
{
public virtual void Method1()
{
Console.WriteLine("Base - Method1");
}
}
class DerivedClass : BaseClass
{
public void Method1() // DerivedClass.Method1() hides inherited memeber BaseClass.Method1(). Use the new keyword if hiding was intended.
{
Console.WriteLine("Derived - Method1");
}
}
class Program
{
static void Main(string[] args)
{
BaseClass bd = new DerivedClass();
bd.Method1();
Console.ReadLine();
}
}
}
You will see that if you use new in declaring Method1() in DerivedClass, bd.Method1() will output: "Base - Method1" as instructed in the base class.
...whereas, if you use override in declaring Method1() in DerivedClass, bd.Method1() will output: "Derived - Method1" as instructed in the derived class.
Why does every source (including the official documentation) say that new hides the base class method, when clearly in this example the base class method is the one invoked when using new?
I understand the different behaviours (new compared to override) but not the terminology.