class Demo_Employee {
public static void main(String[] args) {
Coder c = new Coder("小明","001",6666.6);
c.work();
Manager m = new Manager("小张","000",8888.8,3333);
m.work();
}
}
abstract class Employee {
private String name; //私有化成员变量
private String id; //..........
private double salary; //..........
public Employee() {} //设置空参变量
public Employee(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) { //设置id
this.id=id;
}
public String getId() { //获取id
return id;
}
public void setSalary (double salary) { //设置工资
this.salary=salary;
}
public double getSalary() { //获取工资
return salary;
}
public abstract void work (); //定义抽象方法
}
class Coder extends Employee{
public Coder() {}
public Coder(String name,String id,double salary) {
super(name,id,salary);
}
public void work() {
System.out.println("我的姓名是:"+this.getName()+",我的工号是:"+this.getId()+",我的工资是:"+this.getSalary()+",我的工作内容是敲代码.");
}
}
class Manager extends Employee{
private int bonus; //奖金
public Manager() {}
public Manager(String name,String id,double salary,int bonus) {
super(name,id,salary);
this.bonus=bonus;
}
public void work() {
System.out.println("我的姓名是:"+this.getName()+",我的工号是:"+this.getId()+",我的工资是:"+this.getSalary()+",我的奖金是:"+bonus+",我的工作内容是管理.");
}
}
|
|