static void Main(string[] args)
{
IHomeWork IHW = new Student();
IHW.CollectHomeWork();
Person Stu = new Student();
Stu.Name = "张三";
Stu.Age = 20;
Stu.SaiHi();
IHomeWork ITeacher = new Teacher();
ITeacher.CollectHomeWork();
Person Tea = new Teacher();
Tea.Name = "李四";
Tea.Age = 24;
Tea.SaiHi();
Person XZ = new XiaoZhang();
XZ.Name = "王五";
XZ.Age = 40;
XZ.SaiHi();
Console.ReadKey();
}
public interface IHomeWork//接口,收作业
{
void CollectHomeWork();
}
public abstract class Person
{
public string Name
{ get; set; }
public int Age
{ get; set; }
public abstract void SaiHi();
}
public class Teacher:Person,IHomeWork//继承person类和接口
{
public void CollectHomeWork()
{
Console.WriteLine("老师收作业");
}
public override void SaiHi()
{
Console.WriteLine("我是老师,我叫{0},{1}岁了", Name, Age);
}
}
public class Student : Person, IHomeWork//继承person类和接口
{
public void CollectHomeWork()
{
Console.WriteLine("学生收作业");
}
public override void SaiHi()
{
Console.WriteLine("我是学生,我叫{0},{1}岁了", Name, Age);
}
}
public class XiaoZhang:Person//继承Person类
{
public override void SaiHi()
{
Console.WriteLine("我是校长,我叫{0},{1}岁了",Name,Age);
}
}