Reputation: 3743
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?
Upvotes: 3
Views: 971
Reputation: 1109695
The super()
needs to be the first call in the constructor. Rearrange it above the assert
.
super
(extract below)Invocation of a superclass constructor must be the first line in the subclass constructor.
Upvotes: 6