计算机C#问题,基类中定义了虚方法,派生类中重写了此方法,以下程序有几点不明白
classA{publicvoidF1(){Console.Write("AA");}publicvirtualvoidF2(){Console.Write("BB");...
class A
{ public void F1( ) { Console.Write("AA "); }
public virtual void F2() { Console.Write("BB "); }
}
class B : A
{ new public void F1( ) { Console.Write("CC "); }
public override void F2( ) { Console.Write("DD "); }
}
class Test
{ static void Main()
{ B b = new B();
A a = b; //不明白此处的意义
a.F1();
b.F1();
a.F2(); //不明白此处的执行过程
b.F2();
Console.Read();
}
} 展开
{ public void F1( ) { Console.Write("AA "); }
public virtual void F2() { Console.Write("BB "); }
}
class B : A
{ new public void F1( ) { Console.Write("CC "); }
public override void F2( ) { Console.Write("DD "); }
}
class Test
{ static void Main()
{ B b = new B();
A a = b; //不明白此处的意义
a.F1();
b.F1();
a.F2(); //不明白此处的执行过程
b.F2();
Console.Read();
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询