I’m trying to extend my policy class, which takes a double value.
I tried extending it by
public class DepreciablePolicy extends Policy {
}
But I get an error, “Policy in class policy cannot be applied to given types; required: double, found no arguements”. I was wondering how I can fix this? The extend statement was valid when I made my Policy void, but then the Policy method doesnt work if it’s a void.
public class Policy {
double amount;
int policyNumber;
public static int policyCount = 1;
public Policy(double a){
amount = a;
policyNumber = policyCount;
policyCount ++;
}
public boolean isExpired(){
return false;
}
public void print(){
System.out.print("Policy #" + this.policyNumber + " with amount $" + this.amount);
}
}
As your
Policyclass doesn’t have a no-args default constructor defined, You have to explicitly make a call the super class’s constructor from yourDepreciablePolicyconstructor.