Java中的抽象类和具体类构造函数
我有这个界面:Java中的抽象类和具体类构造函数,java,constructor,abstract-class,Java,Constructor,Abstract Class,我有这个界面: import fondt2.extended.PhoneCall; public interface Rate { public double getCallCost(PhoneCall call); public String getName(); public boolean isApplicableTo(String destinationNumber); public boolean isValid(); } 这个抽象类有自己的构造函数
import fondt2.extended.PhoneCall;
public interface Rate {
public double getCallCost(PhoneCall call);
public String getName();
public boolean isApplicableTo(String destinationNumber);
public boolean isValid();
}
这个抽象类有自己的构造函数:
import fondt2.extended.PhoneCall;
import java.util.Arrays;
public abstract class BandsRate implements Rate {
protected Band[] bands;
protected int intervalInMillis;
protected String name;
protected String numberRoot;
protected double startCallCost;
public BandsRate(String name,Band[] bands, int intervalInMillis, double startCallCost, String numberRoot){
this.name = name;
this.intervalInMillis = intervalInMillis;
this.startCallCost = startCallCost;
this.numberRoot = numberRoot;
this.bands = Arrays.copyOf(bands, bands.length);
}
public abstract double getCallCost(PhoneCall call);
protected double getStartCallCost(){
return this.startCallCost;
}
protected int getIntervalInMillis(){
return this.intervalInMillis;
}
现在我想创建一个具体的类来扩展上面的抽象类:
import java.time.Duration;
import fondt2.extended.*;
public class SimpleBandsRate extends BandsRate {
public SimpleBandsRate(String name, Band[] bands, int intervalInMillis, double startCallCost, String numberRoot){
super(name, bands, intervalInMillis, startCallCost, numberRoot);
}
double getCallCost(PhoneCall call){
double costPerInterval = getCostPerInterval(call.getStart());
if (costPerInterval == -1) {
return -1;
}
long difference = Duration.between(call.getStart(), call.getEnd()).toMillis();
int intervalCount = (int) (difference / super.getIntervalInMillis());
return (double) super.getStartCallCost() + intervalCount * costPerInterval;
}
}
编译器显示了许多错误:如“字符串无法解析为变量”、“标记'numberRoot'上的语法错误删除此标记”、“startCallCost无法解析为变量”等。。我做错了什么?如果您使用的是Eclipse,您可以按照本文中的解决方案尝试使用IDE,其中会突出显示错误您是否手动编写了此代码?或者你是从别的地方复制的?是的。。这是Eclipse的错。。也许自动生成功能让他发疯了!我重新启动,现在它工作了!谢谢如果您正在使用Eclipse,您可以按照本文中的解决方案尝试使用IDE,在IDE中将突出显示错误。您是否手动编写了此代码?或者你是从别的地方复制的?是的。。这是Eclipse的错。。也许自动生成功能让他发疯了!我重新启动,现在它工作了!谢谢