class Employee{
private String name;
private int age;
private float salary;
private Manager m;
public Employee(){
this.name=null;
this.age=0;
this.salary=0.0f;
this.m=null;
}
public Employee(String name,int age,float salary){
this.setName(name);
this.setAge(age);
this.setSalary(salary);
}
public String say(){
return "姓名:"+this.getName()+" 年龄:"+this.getAge()+" 薪水:"+this.getSalary();
}
public void setName(String name){
this.name=name;
}
public String getName(){
return this.name;
}
public void setAge(int age){
this.age=age;
}
public int getAge(){
return this.age;
}
public void setSalary(float salary){
this.salary=salary;
}
public float getSalary(){
return this.salary;
}
public void setM(Manager m){
this.m=m;
}
public Manager getM(){
return this.m;
}
}
class Manager extends Employee{
private int num;
public Manager(){
}
public Manager(String name,int age,float salary,int num){
super(name,age,salary);
this.setNum(num);
}
public String say(){
return super.say()+" 管理人员数:"+this.getNum();
}
public void setNum(int num){
this.num=num;
}
public int getNum(){
return this.num;
}
}
class EmployeeDemo
{
public static void main(String[] args){
Employee e=new Employee("张三",25,5200);
e.say();
Manager m=new Manager("李四",35,12000,30);
m.say();
System.out.println(e.say());
System.out.println(m.say());
}
}
|
|