Employee .java
public class Employee {
private int empId;
private String empName;
private String empsex;
public int getEmpId() {
return empId;
}
public void setEmpId(int empId) {
this.empId = empId;
}
public String getEmpName() {
return empName;
}
public void setEmpName(String empName) {
this.empName = empName;
}
public String getEmpsex() {
return empsex;
}
public void setEmpsex(String empsex) {
this.empsex = empsex;
}
}
PartTimeEmployee.java
public class PartTimeEmployee extends Employee{
private double hourlyPay;
public double getHourlyPay() {
return hourlyPay;
}
public void setHourlyPay(double hourlyPay) {
this.hourlyPay = hourlyPay;
}
}
测试类Test.java
public class Test{
public static void main(String[] args) {
PartTimeEmployee pe=new PartTimeEmployee();
pe.setEmpId(1);
pe.setEmpName("莉莉");
pe.setEmpsex("女");
pe.setHourlyPay(50.0);
System.out.println("雇员编号:"+pe.getEmpId());
System.out.println("雇员姓名:"+pe.getEmpName());
System.out.println("雇员性别:"+pe.getEmpsex());
System.out.println("每小时工资:"+pe.getHourlyPay());
}
}
根据提议是创建关于员工(EMP)的类型;且兼职临时雇员(PTEMP)为继承类;设置日结工资的属性(getHP);引用该类型到具体的对象上(NewPTEMP);输出打印,调用属性信息(Info);
创建类型:关键词:class;字段:private;/public
继承类型:关键词:extends;
设置属性:关键词:public +"字段类型"+setX();(X是方法名称一般为get/set+X结构)
引用类型:关键词:类名 引用名= new 类名();
调用属性:关键词:"."+X