I have two classes
class A
{
public virtual void Metod1()
{
Console.WriteLine("A.Method1");
}
}
class B : A
{
public new void Metod1()
{
Console.WriteLine("B.Method1");
}
}
Then I write some code that declares instances of these classes, and calls their methods
static void Main(string[] args)
{
A a = new B();
a.Metod1();
B b = new B();
b.Metod1();
Console.ReadKey();
}
I gave following result:
A.Method1
B.Method1
But when I delete keyword new from signature method1 of class B and run Main method I got same result. Question:Is new keyword in signature of methods only for better readability?
Edit:Are there cases where we can not do without a new keyword?