这是一个继承问题。我试图了解 TAG1 到 TAG3 的过程。究竟会发生什么并持有哪个类的引用。期待您的建议。
static void Main(string[] args)
{
B b = new B(); **// What Happens here TAG1**
A a = b; **//What Happens here TAG2**
B x = new A() as B; **//what happens here TAG3**
a.F();
a.G();
a.H();
a.Z();
b.F();
b.G();
b.H();
b.Z();
x.F();
Console.ReadLine();
}
public class A
{
public void F() { Console.WriteLine("A.F"); }
public virtual void G() { Console.WriteLine("A.G"); }
public virtual void H() { Console.WriteLine("A.H"); }
public void Z() { Console.WriteLine("A.Z"); }
}
public class B : A
{
new public void F() { Console.WriteLine("B.F"); }
public override void G() { Console.WriteLine("B.G"); }
new public void H() { Console.WriteLine("B.H"); }
}