class Demo{
public static void main(String[] args) {
Manager M=new Manager("张三","23",4444,5555);
M.work();
Programmer P=new Programmer("李四","24",9999);
P.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.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 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("我是项目经理:" + getName() + " 我的工号是:" + getId() + ",我的工资是:" + getSalary()+",我的奖金是:"+ bonus);
}
}
class Programmer extends Employee{
public Programmer(){}
public Programmer(String name, String id, double salary){
super(name,id,salary);
}
public void work() {
System.out.println("我是程序员:" + getName() + " 我的工号是:" + getId() + ",我的工资是:" + getSalary());
}
}
我是项目经理:张三 我的工号是:null,我的工资是:4444.0,我的奖金是:5555
我是程序员:李四 我的工号是:null,我的工资是:9999.0
工号为什么是null |
|