E Spectre
E Spectre

Reputation: 13

Constructor showing 'found no arguments' when arguments provided

new member, first time poster. Please forgive any mistakes or faux pas in my question.

Superclass:

public Person(String n,String pos, String db, String dW, TimePeriods tP,double bS,IManager m){
    setName(n);
    position=Position.valueOf(pos);
    dob=LocalDate.parse(db);
    dateWorking=LocalDate.parse(dW);
    timePeriod=tP;
    baseSalary=bS;
}

Subclass:

private CEO(String n,String pos, String dob, String dW, TimePeriods tP,double bS, IManager m){
}

My error, happening on the subclass CEO constructor:

constructor Person in class Person cannot be applied to given types; required: String,String,String,String,TimePeriods,double,IManager
found: no arguments reason: actual and formal argument lists differ in length

Can anyone help me find out why it isn't finding my arguments?

Upvotes: 1

Views: 316

Answers (1)

Vasu
Vasu

Reputation: 22402

Because you didn't call the Person constructor (using super(..)) inside CEO class constructor, the compiler tries to add the default super() in the first line of CEO constructor.

But, the call default super() fails to compile as you don't have a zero-parameters constructor for Person class.

So, add the super(n, pos, dob, etc..) call in your CEO class as shown below:

public CEO(String n,String pos, String dob, 
        String dW, TimePeriods tP,double bS, IManager m){
  super(n, pos, dob, dw, tP, bS, m);//calls superclass i.e., Person constructor
}

Also, you have got huge argument list for the constructors of your classes, which is very hard to read/maintain, I strongly suggest you need to consider refactoring your classes using Builder pattern (look here) so that it reduces the complexity and the code can be easy to read and maintain.

Upvotes: 2

Related Questions