用c#先定义一个动物类,列出3个属性,两个抽象方法;再定义一个羊类,定义两个属性,两个方法

1个回答

  • using System;

    using System.Collections.Generic;

    using System.Text;

    using System.IO;

    namespace ConsoleApplication1

    {

    public abstract class Animal

    {

    public abstract void Eat();

    public abstract void Jump();

    }

    public class Sheep : Animal

    {

    public override void Eat()

    {

    Console.WriteLine("羊吃草!");

    }

    public override void Jump()

    {

    Console.WriteLine("羊跳栏!");

    }

    }

    class Program

    {

    static void Main(string[] args)

    {

    Animal a = new Sheep();

    a.Eat();

    a.Jump();

    }

    }

    }