核心代码
static void Main(string[] args)
{
//本文来自 www.LuoFenMing.com
Animal animal = new Dog("Dog");
animal.SayName();//输出结果: My Name is Dog
Console.ReadKey();
}
public abstract class Animal
{
public Animal(string name)
{
this.AName = name;
}
public string AName { get; set; }
public abstract void SayName();
}
public class Dog : Animal
{
//继承 Animal必须也要有一个带 一个string类型的构造函数
public Dog(string dName) : base(dName)
{
}
public override void SayName()
{
Console.WriteLine("My Name is " + this.AName);
}
}下面动画为执行过程
