using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace T6
{
/// <summary>
/// 动物抽象类
/// </summary>
abstract class Animal
{
/// <summary>
/// 动物类的抽象方法
/// </summary>
public abstract void Breath();
}
/// <summary>
/// 继承动物抽象类的人类
/// </summary>
abstract class Person : Animal
{
/// <summary>
/// 人类的抽象方法
/// </summary>
public abstract void Study();
public void Eating()
{
Console.WriteLine("Person吃饭.");
}
}
/// <summary>
/// 继承人类的黑人类
/// </summary>
class BlackMan : Person
{
/// <summary>
/// 黑人类重写基类的Breath()方法
/// </summary>
public override void Breath()
{
//以下这句代码是自动生成的
//throw new NotImplementedException();
Console.WriteLine("BlackMan呼吸.");
}
/// <summary>
/// 黑人类重写基类的Study()方法
/// </summary>
public override void Study()
{
//throw new NotImplementedException();
Console.WriteLine("BlackMan学习.");
}
/// <summary>
/// 使用new关键字隐藏基类的Eating()方法
/// </summary>
new public void Eating()
{
Console.WriteLine("BlackMan吃饭.");
}
}
class Program
{
static void Main(string[] args)
{
BlackMan b = new BlackMan();
b.Breath();
b.Eating();
b.Study();
Console.WriteLine("-----------");
Animal a = new BlackMan();
a.Breath();
Console.WriteLine("-----------");
Person p = new BlackMan();
p.Breath();
p.Eating();
p.Study();
Console.Read();
}
}
}