最基础的新手问题不太会
C#抽象类实现4种动物(鸟龟狗鱼)的运动方式输出,如”鱼:飞“{:10_266:} using System;namespace c_
{
public abstract class Animal
{
public abstract void Move();
}
public class Bird : Animal
{
public override void Move()
{
Console.WriteLine("鸟: 飞");
}
}
public class Tortoise : Animal
{
public override void Move()
{
Console.WriteLine("龟: 爬");
}
}
public class Dog : Animal
{
public override void Move()
{
Console.WriteLine("狗: 跑");
}
}
public class Fish : Animal
{
public override void Move()
{
Console.WriteLine("鱼: 游");
}
}
class Program
{
static void Main(string[] args)
{
Animal animal_1 = new Bird();
animal_1.Move();
Animal animal_2 = new Tortoise();
animal_2.Move();
Animal animal_3 = new Dog();
animal_3.Move();
Animal animal_4 = new Fish();
animal_4.Move();
}
}
}
输出
鸟: 飞
龟: 爬
狗: 跑
鱼: 游
yuxijian2020 发表于 2021-4-16 15:42
输出
感谢大佬!
页:
[1]