/*
1. 定义员工Employee类。包含属性:姓名,工号,部门。
* */
public class Employee {
private String name;
private int id;
private String department;
public Employee() {
}
public Employee(String name, int id, String department) {
this.name = name;
this.id = id;
this.department = department;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getDepartment() {
return department;
}
public void setDepartment(String department) {
this.department = department;
}
public void show(){
System.out.print(department + "的:"+name);
System.out.println(",员工编号;"+id);
}
}
/*
定义经理Manager类继承Employee类,包含属性:职员(该经理的职员)
* */
public class Manager extends Employee {
private String heeler;
public Manager(){
}
public Manager(String name, int id, String department, String heeler) {
super(name, id, department);
this.heeler = heeler;
}
public String getHeeler() {
return heeler;
}
public void setHeeler(String heeler) {
this.heeler = heeler;
}
@Override
public void show() {
super.show();
System.out.println("他的职员是:"+ heeler);
}
}
/*定义职员Clerk类继承Employee类,包含属性:经理(该职员的经理)
* */
public class Clerk extends Employee{
private String lead;
public Clerk() {
}
public Clerk(String name, int id, String department, String lead) {
super(name, id, department);
this.lead = lead;
}
public String getLead() {
return lead;
}
public void setLead(String lead) {
this.lead = lead;
}
@Override
public void show() {
super.show();
System.out.println("他的领导是:"+lead);
}
}
//测试类中测试
import java.sql.SQLOutput;
public class Demo {
public static void main(String[] args) {
/*Employee e = new Employee("朱七",28,"销售部门");
e.show();
System.out.println("==============");*/
Manager m = new Manager();
m.setName("张三");
m.setId(38);
m.setDepartment("销售部门");
m.setHeeler("李四");
// System.out.println(m.getName()+", "+m.getId()+", "+m.getDepartment()+", "+m.getHeeler());
m.show();
System.out.println("==================================");
Clerk c = new Clerk("王五",48,"销售部门","孙六");
//System.out.println(c.getName()+", "+c.getId()+", "+c.getDepartment()+", "+c.getLead());
c.show();
}
} |
|