ERROR:Implicit super constructor Person() is undefined for default constructor. Must define an explicit constructor
这个错误是你的父类中的构造器是有参数的,所以在你的子类中,你必须显式的调用父类的构造函数
例如:
abstract class Person{
public abstract String getDescription();
private String name;
public Person(String name) {
this.name = name;
}
public String getName() {
return name;
}
}
class Employee extends Person {
private double salary;
private LocalDate hireDay;
public Employee(String name, double s, int year, int month, int day) {
super(name); //显式的调用父类的构造函数
//super(); //这个不可以
s = salary;
hireDay = LocalDate.of(year,month,day);
}
本文解释了在Java中如何正确地从子类构造器调用父类构造器,特别是当父类构造器需要参数时的情况。通过一个具体的例子展示了正确的调用方式。
1212

被折叠的 条评论
为什么被折叠?



