首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

base.base不行?该如何解决

2013-01-22 
base.base不行?using Systemusing System.Collections.Genericusing System.Linqusing System.Textusi

base.base不行?

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;

namespace Csharp
{
    class Animal
    {
        public void speak()
        {
            Console.WriteLine("I am Animal");
        }
    }
    class Monkey : Animal
    {
        public void speak()
        {
            Console.WriteLine("I am Monkey");
        }
    }
    class People : Monkey
    {
        public void speak()
        {
            base.base.speak();
            Console.WriteLine("and");
            Console.WriteLine("I am People");
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            People p = new People();
            p.speak();
            Console.ReadKey();
        }

    }
}

1>------ 已启动生成: 项目: Csharp, 配置: Debug Any CPU ------
1>C:\Users\ys\Desktop\Csharp\Csharp\Program.cs(19,21,19,26): warning CS0108: “Csharp.Monkey.speak()”隐藏了继承的成员“Csharp.Animal.speak()”。如果是有意隐藏,请使用关键字 new。
1>C:\Users\ys\Desktop\Csharp\Csharp\Program.cs(26,21,26,26): warning CS0108: “Csharp.People.speak()”隐藏了继承的成员“Csharp.Monkey.speak()”。如果是有意隐藏,请使用关键字 new。
1>C:\Users\ys\Desktop\Csharp\Csharp\Program.cs(28,18,28,22): error CS1041: 应输入标识符;“base”是关键字
========== 生成: 成功 0 个,失败 1 个,最新 0 个,跳过 0 个 ==========
[解决办法]
这样就行了

class Animal
        {
            public void speak()
            {
                Console.WriteLine("I am Animal");
            }
        }
        class Monkey : Animal
        {
            public new void speak()


            {
                Console.WriteLine("I am Monkey");
            }
        }
        class People : Monkey
        {
            public new void speak()
            {
                ((Animal)this).speak();
                Console.WriteLine("and");
                Console.WriteLine("I am People");
            }
        }

热点排行