标题: 多态啊,纠结的我D疼 [打印本页] 作者: ARMdong 时间: 2012-9-1 01:09 标题: 多态啊,纠结的我D疼 class A
{
public string Str = "A";
public void Show() { Console.WriteLine("Show A"); }
}
class B : A
{
public string Str = "B";
public virtual void Show() { Console.WriteLine("Show B"); }
}
class C : B
{
public override void Show() { Console.WriteLine("Show C"); }
}
class D : C
{
public string Str = "D";
public void Show() { Console.WriteLine("Show D"); }
}
class Program
{
static void Main(string[] args)
{
D d = new D();
C c = d;
B b = d;
A a = d;
Console.WriteLine(d.Str);
Console.WriteLine(c.Str);
Console.WriteLine(b.Str);
Console.WriteLine(a.Str);
Console.WriteLine("------------");
d.Show();
c.Show();
b.Show();
a.Show();
Console.ReadLine();
}
}
各位大仙,帮我分析下这个流程怎么走吧!我快疯了……