一、设计思想
二、主要源代码
(using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace extendAndPolymorphism
{
internal class Program
{
static void Main(string[] args)
{
var d = new D();
d.MyMethod(0);
var e = new E();
e.MyMethod(0);
string d1 = d.Result;
string e1 = e.Result;
Console.WriteLine("传参都为0,结果一个为10,第二个为50");
Console.WriteLine("d.MyMethod(0)={0},e.MyMethod(0)={1}",d1,e1);
Console.ReadLine();
}
class D
{
public string Result { get; protected set; } = " ";
public virtual void MyMethod(int num)
{
this.Result = (num+10).ToString();
}
}
class E : D
{
public string Result;
public override void MyMethod(int num)
{
this.Result = (num+50).ToString();
}
}
}
}
C#程序设计实验7 类继承-虚拟和重写
猜你喜欢
转载自blog.csdn.net/qq_62480054/article/details/131585531
今日推荐
周排行