public abstract class Person
{
private string name;
public Person(string name)
{
this.name = name;
}
public abstract void speaking();
public virtual void eatting()
{
Console.WriteLine("Person is eatting...");
}
public void sleeping()
{
Console.WriteLine("Person is sleeping...");
}
}
public class Child : Person
{
private int id;
public Child(string name,int id) : base(name)
{
this.id = id;
}
public override void speaking()
{
Console.WriteLine("Child is speaking...");
}
public override void eatting()
{
base.eatting();
Console.WriteLine("Child is eatting");
}
public new void sleeping()
{
Console.WriteLine("Child is sleeping...");
}
}
public class Adult : Person
{
private int id;
public Adult(string name,int id) : base(name)
{
this.id = id;
}
public override void speaking()
{
Console.WriteLine("Adult is speaking...");
}
public override void eatting()
{
base.eatting();
Console
c#:类的继承中Abstract 、Virtual和Override的使用
最新推荐文章于 2021-11-04 16:15:29 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)