爪哇岛。隐式超构造函数 Employee() 未定义。必须显式调用另一个构造函数
2022-09-01 15:37:32
您好,我是Java的新手,我在生产工人类中遇到了这个错误。我的生产工作线程构造函数说显式调用另一个构造函数。我不知道该怎么办?。
import java.util.Date;
public class Employee
{
private String name, number;
private Date date;
public Employee(String name, String number, Date date)
{
setName(name);
setNumber(number);
setDate(date);
}
public void setName(String n)
{
name = n;
}
public void setNumber(String n)
{
number = n;
// you can check the format here for correctness
}
public void setDate(Date d)
{
date = d;
}
public String getName()
{
return name;
}
public String getNumber()
{
return number;
}
public Date getDate()
{
return date;
}
}
public class ProductionWorker extends Employee
{
private int shift;
private double hourlyrate;
// error is here (Implicit super constructor Employee() is undefined. Must explicitly invoke another constructor).
public ProductionWorker(int shift, double hourlyrate)
{
setShift(shift);
setHourlyPayRate(hourlyrate);
}
public void setShift(int s)
{
shift = s;
}
public void setHourlyPayRate(double rate)
{
hourlyrate = rate;
}
public int getShift()
{
return shift;
}
public double getHourlyPayRate()
{
return hourlyrate;
}
}