110,539
社区成员
发帖
与我相关
我的任务
分享
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();
}
}
public override void ShowType()
{
base.ShowType();
}
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();
}
}