Below I have some simple code with a Parent Class and a Child one that extends from it.
using System;
//Base Class
public class Parent {
public void foo() {
Console.WriteLine("Parent");
}
}
//Child Class
public class Child : Parent
{
new public void foo() {
Console.WriteLine("child");
}
}
Parent parent = new Child();
parent.foo();
I'm confused as to how the two lines above work. I would've expected the compiler to bark while trying to instantiate a Parent as its own subclass. Also, why then would 'parent.foo()' still call its Parent version.