public class CompanyTest { public static void main(String[] args) { //创建程序员对象,并对属性赋值 Programer e = new Programer("小红","001",8888); //获取值 System.out.println(e.getName() + " "+e.getId() +" "+e.getSalary()); //调用方法 e.work(); ProjectManager pm = new ProjectManager("小明","002",6666,8000); System.out.println(pm.getName() +" " + pm.getId() + " "+ pm.getSalary() +" "+ pm.getBouns()); pm.work(); } } abstract class Emplyee //员工 { //姓名,工号,工资 private String name; private String id;//工号 private double salary;//工资 //构造方法 public Emplyee(){} public Emplyee(String name, String id, double salary){ this.name = name; this.id = id; this.salary = salary; } //公共方法 public void setName(String name){ this.name = name; } public String getName(){ return name; } public void setId(String id){ this.id = id; } public String getId(){ return id; } public void setSalary(double salary){ this.salary = salary; } public double getSalary(){ return salary; } public abstract void work(); } class Programer extends Emplyee// 程序员 { //构造方法 public Programer(){} public Programer(String name, String id, double salary){ super(name,id,salary); } public void work(){ System.out.println("程序员工作"); } } class ProjectManager extends Emplyee// 项目经理 { //成员变量 private double bouns; //奖金 //构造方法 public ProjectManager(){} public ProjectManager(String name, String id, double salary, double bouns){ super(name,id,salary); this.bouns = bouns; } //公共访问方法 setXxx, getXxx() public void setBouns(double bouns){ this.bouns = bouns; } public double getBouns(){ return bouns; } public void work(){ System.out.println("项目经理工作"); } } |