class Animal
{
public void Foo() { Console.WriteLine("Animal::Foo()"); }
}
class Cat : Animal
{
public void Foo() { Console.WriteLine("Cat::Foo()"); }
}
class Test
{
static void Main(string[] args)
{
Animal a;
a = new Cat();
a.Foo(); // output --> "Animal::Foo()"
}
}
编译器警告说:
Cat.Foo 隐藏了继承的成员
然而,输出实际上来自基类。所以对我来说,似乎反过来,我调用的那个被基类中的那个隐藏了。