例如,
public class Foo
{
public virtual bool DoSomething() { return false; }
}
public class Bar : Foo
{
public override bool DoSomething() { return true; }
}
public class Test
{
public static void Main()
{
Foo test = new Bar();
Console.WriteLine(test.DoSomething());
}
}
Run Code Online (Sandbox Code Playgroud)
为什么答案是真的?"新酒吧()"是什么意思?"new Bar()"是不是意味着分配内存?