public abstract class Fish
{
public abstract string Name { get; set; }
public abstract void Introduce();
}
public class Catfish : Fish
{
public Catfish()
{
}
public Catfish(string name)
{
Name = name;
}
public override string Name { get; set; }
public override void Introduce()
{
Console.WriteLine($"{Name},是一条鲶鱼!");
}
}
public class Carp : Fish
{
public Carp(string name)
{
Name = name;
}
public override string Name { get; set; }
public override void Introduce()
{
Console.WriteLine($"{Name},是一条鲤鱼!");
}
}
public class Goldfish : Fish
{
public Goldfish(string name)
{
Name = name;
}
public override string Name { get; set; }
public override void Introduce()
{
Console.WriteLine($"{Name},是一条金鱼!");
}
}
Fish catfish = new Catfish("多多");
catfish.Introduce();
Fish carp = new Carp("花花");
carp.Introduce();
Fish goldfish = new Goldfish("贝塔");
goldfish.Introduce();