第1个回答 2020-03-19
public class Demo {
public static void main(String[] args) {
Employee employee = new Employee("003", "张三");
Manager manager = new Manager("002", "李四", "财务部");
Chairman chairman = new Chairman("001", "王麻子");
employee.showInfo();
employee.work();
manager.showInfo();
manager.work();
chairman.showInfo();
chairman.work();
}
}
class Employee {
private String identifier;
private String name;
public Employee(String identifier, String name) {
this.identifier = identifier;
this.name = name;
}
public void work() {
System.out.println("工作时间:周一至周五,朝九晚五");
}
public void showInfo() {
System.out.println("职工编号" + this.identifier + ", 职工姓名: " + this.name);
}
public String getIdentifier() {
return identifier;
}
public void setIdentifier(String identifier) {
this.identifier = identifier;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
class Manager extends Employee {
private String department;
public Manager(String identifier, String name, String department) {
super(identifier, name);
this.department = department;
}
@Override
public void showInfo() {
System.out.println("职工编号" + this.getIdentifier() + ", 职工姓名: " + this.getName() + ", 工作部门: " + this.department);
}
public String getDepartment() {
return department;
}
}
class Chairman extends Employee {
public Chairman(String identifier, String name) {
super(identifier, name);
}
@Override
public void work() {
System.out.println("董事长主持召开股东大会");
}
}本回答被提问者和网友采纳