-2

您好,当我运行我的代码时,我收到“java:在调用超类型构造函数之前无法引用它”错误。我怎样才能解决这个问题?

public class Premiumhosting extends Hosting{
public int Hosting_fee=0;

public boolean setsignupFeePaid;
public Premiumhosting(String server, String website, String livesupport, String siteDomain, int ram, boolean sethostingFeePaid) {
    super(server, website, livesupport, siteDomain, ram, this.Hosting_fee);
    this.sethostingFeePaid=sethostingFeePaid;
}

public double calculateRam(double purchaseAmount){
    if(sethostingFeePaid){
        return (5*purchaseAmount);

    }
}

}

4

1 回答 1

0

this.Hosting_fee is not initialized yet and cannot be - it is therefore always 0. If your code had worked, replacing this.Hosting_fee with 0 would have done the same thing. What are you trying to accomplish? If it's just 'pass 0', then.. just replace this.Hosting_fee with 0. If that wasn't your intent, perhaps update the question or ask a new one, I'm having a hard time trying to figure it out :)

于 2021-02-24T01:47:27.017 回答