为了账号安全,请及时绑定邮箱和手机立即绑定

求帮忙看下哪儿错了

using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks; 
namespace PetShop
{
    struct fish
    {
        int weight;
        int size;
        int type;
    }
    interface ICatchMice    {
        void CatchMice();
    }
    interface IClimbTree    {
        void climbTree();
    }
    abstract public class Pet    {
        public Pet(string name)
        {
            _name = name;
        }
        protected string _name;
        public void PrintName()
        {
            Console.WriteLine("Pet's name is " + _name);
        }
        //public uint age;        //public string food;        abstract public void Speak();
        virtual public void Move()
        {
 
        }
       
    }
    public class Dog:Pet    {
        static int Num;
        static Dog()
        {
            Num = 0;
        }
        public Dog(string name):base(name)
        {
            ++Num;
        }
        new public void PrintName()
        {
            Console.WriteLine("宠物的名字是 " + _name);
        }
        sealed override public void Speak()
        {
            Console.WriteLine(_name + " is speaking" + " wow");
        }
        override public void Move()
        {
 
        }
        static public void ShowNum()
        {
            Console.WriteLine("Dog's number = " + Num);
        }
    }
    public class Labrador : Dog    {
        public Labrador(string name):base(name)
        {
 
        }
    }
    public class Cat:Pet,ICatchMice,IClimbTree    {
        public Cat(string name):base(name)
        {
     
        }
        override public void Speak()
        {
            Console.WriteLine(_name + " is speaking" + " meow");
        }
        public void CatchMice()
        {
            Console.WriteLine(" Catch mice");
        }
        public void ClimbTree()
        {
            Console.WriteLine(" Climb tree");
        }
    }
 
    class Program    {
        static void Main(string[] args)
        {
            Pet[] pets = new Pet[] {new Dog("Jack"),new Cat("Tom")};
            //Pet dog = new Dog();            //dog.PrintName();            //dog.Speak();            ////Pet cat = new Cat();            //cat.PrintName();            //cat.Speak();            for (int i = 0; i < pets.Length; ++i)
            {
                pets[i].Speak();
            }
            Cat c = new Cat("Tom2");
            IClimbTree climb = (IClimbTree)c;
            c.ClimbTree();
            climb.ClimbTree();
            ICatchMice catchM = (ICatchMice)c;
            c.CatchMice();
            catchM.CatchMice();
 
            Dog.ShowNum();
        }
    }
}

https://img1.sycdn.imooc.com//5bd319cd00012fd912030719.jpg

正在回答

4 回答

的我

https://s.cnr.cn/index_sub.html?key=%E4%B9%B0%E7%90%83%E5%B9%B3%E5%8F%B0%E3%80%90%E5%AE%98%E7%BD%91%EF%BC%9AY%D0%92%E2%91%A1%E2%91%A4%E2%91%A1.%D0%A1%D0%A1%E3%80%91


0 回复 有任何疑惑可以回复我~
#1

qq_慕仔2384744

https://s.cnr.cn/index_sub.html?key=%E4%B9%B0%E7%90%83%E7%9A%84app%E6%8E%A8%E8%8D%90%E3%80%90%E5%AE%98%E7%BD%91%EF%BC%9AY%D0%92%E2%91%A1%E2%91%A4%E2%91%A1.%D0%A1%D0%A1%E3%80%91
2022-06-03 回复 有任何疑惑可以回复我~
#2

qq_慕仔2384744

https://s.cnr.cn/index_sub.html?key=%E6%AD%A3%E8%A7%84%E8%B5%8C%E8%B6%B3%E7%90%83%E7%9A%84app%E3%80%90%E5%AE%98%E7%BD%91%EF%BC%9AY%D0%92%E2%91%A1%E2%91%A4%E2%91%A1.%D0%A1%D0%A1%E3%80%91
2022-06-03 回复 有任何疑惑可以回复我~
#3

qq_慕仔2384744

https://s.cnr.cn/index_sub.html?key=%E6%AD%A3%E8%A7%84%E4%B9%B0%E7%90%83app%E5%8D%81%E4%BD%B3%E6%8E%92%E8%A1%8C%E3%80%90%E5%AE%98%E7%BD%91%EF%BC%9AY%D0%92%E2%91%A1%E2%91%A4%E2%91%A1.%D0%A1%D0%A1%E3%80%91
2022-06-03 回复 有任何疑惑可以回复我~

第一点错误,派生类重写基类的方法,基类没有方法

 virtual  public void Speak()

        {

         }

第二点错误,你声明接口,

void climbTree();
C是小写,你调用又是大写,所以提示错误。


0 回复 有任何疑惑可以回复我~

好像类中写的ClimbTree()方法是小写的 调用的时候是大写的吧

0 回复 有任何疑惑可以回复我~

    interface IClimbTree

    {

        void ClimbTree();

    }

大写啊ClimbTree();

0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

求帮忙看下哪儿错了

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信