package com.test;
public class Employee {
private String name;
private int id;
private String address;
private double salary;
public Employee(){ //无参构造器
}
public Employee(String name,int id,String address,double salary){ //构造器
this.name = name;
this.id = id;
this.address = address;
this.salary = salary;
}
public double js(){ //计算工资的方法
return 0;
}
public String print() { //输出员工基本信息
return "姓名:" + name + " 职工号:" + id + " 地址:" + address;
}
public String getName() { //对一些属性的设置和修改方法
return name;
}
public void setName(String name) {
this.name = name;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public double getSalary() {
return salary;
}
public void setSalary(double salary) {
this.salary = salary;
}
public static void main(String[] args) {
ZsEmp z = new ZsEmp();
z.setName("
正式员工");
z.setId(1001);
z.setAddress("China");
LsEmp l = new LsEmp();
l.setName("临时员工");
l.setId(1002);
l.setAddress("China");
Employee[] emps = new Employee[2];
emps[0] = z;emps[1] = l;
for(Employee e : emps){
System.out.println(e.print()+",他的工资:"+e.js());
}
}
}
class ZsEmp extends Employee{ //正式员工
@Override
public double js() {
double s = 3000; //不知道具体的计算方法是怎样,这里简单写了
return s;
}
}
class LsEmp extends Employee{ //临时员工
@Override
public double js() {
double s = 1000;
return s;
}
}