using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace animal_woof
{
public abstract class Animal
{
// public string Name { get; set; }
public abstract void MakeSound();
public virtual void Eat()
{
Console.WriteLine("This animal eats food.");
}
}
public class Lion:Animal
{
public override void MakeSound()
{
Console.WriteLine("Roar!!!");
}
public override void Eat()
{
Console.WriteLine("This animal eats meat.");
}
}
public class Dog : Animal
{
public override void MakeSound()
{
Console.WriteLine("Woof!!!");
}
// public void Eat() { }
}
internal class Program
{
static void Main(string[] args)
{
Dog dog = new Dog();
dog.MakeSound();
dog.Eat();
Lion lion = new Lion();
lion.MakeSound();
lion.Eat();
}
}
}
简单的抽象类的继承,抽象方法,虚方法的继承示例
于 2024-09-30 11:12:38 首次发布