是多态还是变态,请指教

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

public int secondMethod()
{ return(10); }

public int thirdMethod()
{ return(20); } }

class DerivedClass : SecondExp
{
public new int secondMethod()
{ return (30); }
}
class Test
{
public static void Main()
{

//第一种:
SecondExp objDerived = new DerivedClass();
objDerived.secondMethod(); //注意这种方法
//第二种:
DerivedClass objDerived = new DerivedClass();
objDerived.secondMethod(); //注意这种方法

System.Console.WriteLine(objDerived.firstMethod());
}
}
...全文
评论 12
收藏 已收藏
分享
返回顶部
king2003
.NET社区 62,273 成员 668,968 内容