题目是创建员工数组,分别创建若干不同的员工对象,并打印某个月工资
public class main {
public static void main(String[]args) {
Employee[] em =new Employee[] {
new Salariedmploye("李华",7,5000),
new HourlyEmploye ("李丽",9,100,180),
new SalesEmploye ("边五",5,5600,0.56),
new BasePlusSalesEmploye("苏卿",30,3000,0.56,5000),
};
for (int i=0;i< em.length;i++) {
**print(em [i],5); ** (这句报错了 错误是: Cannot make a static reference to the non-static method print(Employee,int) from the type main )请问为什么这句会报错
}
}
public void print(Employe e,int mouth) {
System.out.println("该员工的工资为:"+e.getSalary(mouth));
}
}
class Employe {
private String name;
private int mouth;
public Employee(String name,int mouth) {
this.name=name;
this.mouth=mouth;
}
public double getSalary(int mouth){
if(mouth != this.mouth) {
return 0.0;
}
else {
return 100.0;
}
}
}
class SalariedEmploye extends Employe{
private double salary;
public SalariedEmploye(String name,int mouth,double salary) {
super(name,mouth);
this.salary=salary;
}
public double getSalary(int mouth) {
double pride= super.getSalary(mouth);
return salary+pride;
}
}
这是部分 后面都没报错