一个很基础的问题,大家说说看法

周公 周公 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
using System;

namespace VirtualDemo
{
/// <summary>
/// Class1 的摘要说明。
/// </summary>
class Class1
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main(string[] args)
{
Son son=new Son();
Father father=son;
father.MyFun();
son.MyFun();
father.MyGun();
son.MyGun();
Console.ReadLine();
}
}

public class Father
{
public void MyFun()
{
Console.WriteLine("Father.MyFun()");
}

public virtual void MyGun()
{
Console.WriteLine("Father.MyGun()");
}
}

public class Son:Father
{
public new void MyFun()
{
Console.WriteLine("Son.MyFun()");
}

public override void MyGun()
{
Console.WriteLine("Son.MyGun()");
}

}
}

大家看看最后是什么结果,说说你的理由。
...全文
评论 11
收藏 已收藏
分享
返回顶部
周公
周公 领域专家: 后端开发技术领域 领域专家: 后端开发技术领域
C# 111,130 成员 642,539 内容