I've just read that when you define a method in a derived class that has the same name as a method described in a base class, you should get the error: "please add the 'override' or 'new' keyword". But despite me trying to cause it to do so by the code below, everything seems to be OK.
I'd like to know why? I use Visual Studio 2010.
class Base
{
public void Method()
{
Console.WriteLine("Base class");
}
}
class Child : Base
{
public void Method()
{
Console.WriteLine("Child class");
}
}
static void Main(string[] args)
{
Base myBase = new Base();
Child myChild = new Child();
myBase.Method();
myChild.Method();
}
The output I'm getting is as follows.
Base class
Child class