Java Inheritance - cannot find character constructor

I can't figure out how to compile my subclass even if it calls the superclass constructor?

This is a class that will not compile:

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;
    }

}

This is a superclass:

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;
    }

}

The subclass goes on to say "cannot find character - Employee constructor". These two are in different packages. Did I knit them correctly?

+3
source share
1 answer

The constructor super()must have a first call . Reorder it higher assert.

See also:

The call to the constructor of the superclass should be the first line in the constructor of the subclass.

+6
source

Source: https://habr.com/ru/post/1791389/


All Articles