Java继承 - 找不到符号构造函数

3

尽管调用了父类的构造函数,但我还是无法编译我的子类?

这是无法编译的类:

package departments;
import employees.*;

public class DepartmentEmployee extends Employee{

    private Department department;

    public DepartmentEmployee(Profile profile, Address address, Occupation occupation,   Department department) {
        assert (department != null) : "invalid Department";
        super(profile, address, occupation);
        this.department = department;
    }

}

这是超类:

package employees;

public class Employee {

    protected Profile profile;
    protected Address address;
    protected Occupation occupation;

    protected Employee(Profile profile, Address address, Occupation occupation) {
        assert (profile != null) : "invalid Profile";
        assert (address != null) : "invalid Address";
        assert (occupation != null) : "invalid Occupation";
        this.profile = profile;
        this.address = address;
        this.occupation = occupation;
    }

}

子类一直报错“找不到符号 - 构造函数Employee”。它们在不同的包中。我是否正确链接它们?

2
在你的 DepartmentEmployee 类中,应该不是用 super(...) 作为构造函数的第一个调用吗? - user499054
1个回答

6
super()需要在构造函数中的第一次调用。请将其排在assert之前。

另请参阅:

在子类构造函数中,对父类构造函数的调用必须是第一行。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接