public abstract class Animal
{
    public abstract void ShowType();
    public void Eat()
    {
        Console.WriteLine("Animal always eat.");
    }
}
public class Bird : Animal
{
    private string type = "bird";    public override void ShowType()
    {
        Console.WriteLine("Type is {0}.", type);
    }    private string color;
    public string Color
    {
        get { return color; }
        set { color = value; }
    }
}public class Chicken : Bird
{
    private string type = "chicken";    public void ShowColor()
    {
        Console.WriteLine("color is {0}.", Color);
    }
}
class Program
{
    static void Main(string[] args)
    {
        Chicken chicken = new Chicken();
        chicken.ShowType();        Console.ReadKey();
    }
}
请问输出的是什么???
麻烦说说原因????

解决方案 »

  1.   

    先发一通牢骚,我晕啊,因为网速太慢的原因,点击提交后半天没有动静,于是又点击了一边提交,害我发了两个一模一样的帖子!!!CSDN这个问题没法该吗???
      

  2.   

    看错了
    Type is bird.但是,这只能说你程序写的烂。
      

  3.   

    Type is bird
    貌似不能覆盖字段的
      

  4.   

    Type is bird.寻找ShowType()方法,一路找到Bird类中的ShowType()方法,因为Chicken类继承自Bird类且没有重写这个方法。
      

  5.   

    2个类得type变量不一样呢.
    实际输出为Chicken类的基类Bird类ShowType()方法.public override void ShowType()
        {
            base.ShowType();
        }如果要输出Type is chicken。using System;
    public abstract class Animal
    {
        public abstract void ShowType();
        public void Eat()
        {
            Console.WriteLine("Animal always eat.");
        }
    }
    public class Bird : Animal
    {
        protected string type = "bird";    public override void ShowType()
        {
            Console.WriteLine("Type is {0}.", type);
        }    private string color;
        public string Color
        {
            get { return color; }
            set { color = value; }
        }
    }public class Chicken : Bird
    {
        public Chicken()
        {
            this.type = "chicken";
        }    public void ShowColor()
        {
            Console.WriteLine("color is {0}.", Color);
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            Chicken chicken = new Chicken();
            chicken.ShowType();        Console.ReadKey();
        }
    }
      

  6.   

    Type is bird.
     chicken.ShowType();中的chicken没有实现ShowType方法,调用Bird方法重写的ShowType方法。
      

  7.   

    Bird类重写了Animal类的ShowType方法
    而Chicken类继承了Bird类的ShowType一个是重写,一个是继承
      

  8.   

    请帮忙回复一下这个帖子,这个帖子的分数都给你!!
    http://topic.csdn.net/u/20110427/21/8f5630b5-da0d-42e6-9d1c-4a3257eb30e2.html
      

  9.   

    Type is birdChicken 类里面没有ShowType所以在它的父类中寻找。所以 调用的是bird类的ShowType方法。
      

  10.   


    讲的是集成方面的(后面是讨论继承还是聚合类的问题),原本代码中chicken类是重写了ShowType()方法的
    是我好奇,于是将chicken类中的ShowTyup()方法去掉然后把题目拿过来!!!看你这语气我想也没有必要说什么了。。我只是菜鸟一只,或许你根本就不屑我的回答。。不过没关系,我只是朝我认为正确的方向走!!!
      

  11.   

    本帖最后由 caozhy 于 2011-04-28 15:24:03 编辑