class Class1
{
static void Main(string[] args)
{
YuanGong yg = new YuanGong();
JingLi jl = new JingLi();
LaoBan lb = new LaoBan(); //声明一个数组的父类
YuanGong[] ayg = { yg, jl, lb };
//遍历数组
for (int i = ; i < ayg.Length; i++)
{
ayg[i].DaKa();
}
Console.ReadKey();
} }
public class YuanGong
{
//virtual虚拟,在子类中改变后,用父类实例化子类后可以调用子类方法
public virtual void DaKa()
{
Console.WriteLine("员工九点打卡");
}
}
public class JingLi:YuanGong
{
//override 接收对应 virtual
public override void DaKa()
{
Console.WriteLine("经理十点打卡");
}
}
public class LaoBan:YuanGong
{
public override void DaKa()
{
Console.WriteLine("老板不打卡");
}
}
05-04 02:08