3

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

This is the class that won't 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 the 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 keeps on saying "cannot find symbol - constructor Employee". The two are in different packages. Did I link them correctly?

1
  • 2
    In your DepartmentEmployee, shouldn't super(...) be the first call in the ctor? Commented Feb 11, 2011 at 2:53

1 Answer 1

6

The super() needs to be the first call in the constructor. Rearrange it above the assert.

See also:

Invocation of a superclass constructor must be the first line in the subclass constructor.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.