using
System;
abstract class Employee // 定义抽象类
... {
protected string _name;//只被本类或派生类访问
protected Employee()//默认构造函数
...{
}
protected Employee(string name)//带一个参数的构造函数
...{
_name = name;
}
abstract public void strartWork();//抽象方法
}
class Manager : Employee
... {
public Manager(string name): base(name)//指定构造函数
...{ }
public override void strartWork()//重写基类虚方法
...{
Console.WriteLine(_name+"给员工下达任务");
}
}
class xs : Employee
... {
public xs(string name):base(name)//指定构造函数
...{ }
public override void strartWork()
...{
Console.WriteLine(_name + "销售产品");
}
}
class ms : Employee
... {
public ms(string name) : base(name)//指定构造函数
...{ }
public override void strartWork()
...{
Console.WriteLine(_name + "经理助理");
}
}
class kj : Employee
... {
public kj(string name) : base(name)//指定构造函数
...{ }
public override void strartWork()
...{
Console.WriteLine(_name + "财务核算");
}
}
class Test
... {
static void Main()
...{
Employee [] emp =new Employee[4];//并没有实例化Employee抽象类,而是建立了一个Employee类型的数组,new的是数组
emp[0]=new Manager("张三");
emp[1]=new xs("李四");
emp[2]=new ms("王五");
emp[3]=new kj("赵六");
Console.WriteLine("上午8点开始工作:");
foreach(Employee e in emp)
...{
e.strartWork();
}
}
}
abstract class Employee // 定义抽象类
... {
protected string _name;//只被本类或派生类访问
protected Employee()//默认构造函数
...{
}
protected Employee(string name)//带一个参数的构造函数
...{
_name = name;
}
abstract public void strartWork();//抽象方法
}
class Manager : Employee
... {
public Manager(string name): base(name)//指定构造函数
...{ }
public override void strartWork()//重写基类虚方法
...{
Console.WriteLine(_name+"给员工下达任务");
}
}
class xs : Employee
... {
public xs(string name):base(name)//指定构造函数
...{ }
public override void strartWork()
...{
Console.WriteLine(_name + "销售产品");
}
}
class ms : Employee
... {
public ms(string name) : base(name)//指定构造函数
...{ }
public override void strartWork()
...{
Console.WriteLine(_name + "经理助理");
}
}
class kj : Employee
... {
public kj(string name) : base(name)//指定构造函数
...{ }
public override void strartWork()
...{
Console.WriteLine(_name + "财务核算");
}
}
class Test
... {
static void Main()
...{
Employee [] emp =new Employee[4];//并没有实例化Employee抽象类,而是建立了一个Employee类型的数组,new的是数组
emp[0]=new Manager("张三");
emp[1]=new xs("李四");
emp[2]=new ms("王五");
emp[3]=new kj("赵六");
Console.WriteLine("上午8点开始工作:");
foreach(Employee e in emp)
...{
e.strartWork();
}
}
}