•
在一个公司管理信息系统中,包括
▫
普通员工(
Employees)
,
其可能有的属性信息包括
–
员工号(
employeeNumber
)
–
姓名(
name
)
–
地址(
address
)
–
工作年限(
year
)
–
工资 基本工资
2000
元
+
年限*
100
▫
管理者(
Magagers
)
,
除具有普通员工所具有的属性及行为外,还具有下面的属性和行为
–
职责(
responsibilities
)
–
工资的计算方法与一般员工不同;普通员工的基本工资
2
倍
+
年限
*200
–
试用继承方式实现该功能
–
父类代码:
package com.Sru;
public class Person {
protected String employeeNumber, name, address ;
int salary,year;
public Person(){
}
public Person(String eEmployeeNumber,String nName, String aAddress,int sSalary,int yYear){
employeeNumber = eEmployeeNumber;
name = nName;
address = aAddress;
year = yYear;
salary = sSalary;
}
public int salary(){
return (salary=2000+(int)(year)*100);
}
}
子类代码
package com.Sru;
public class Son extends Person {
protected String responsibilities;int salary;
public Son (String rResponsibilities, int sSalary) {
responsibilities = rResponsibilities;
salary = sSalary;
}
public int salary(){
return (salary=4000+(int)(year)*200);
}
}