在 Java 中,为什么会出现此错误:
Error: The constructor WeightIn() is undefined
Java代码:
public class WeightIn{
private double weight;
private double height;
public WeightIn (double weightIn, double heightIn){
weight = weightIn;
height = heightIn;
}
public void setWeight(double weightIn){
weight = weightIn;
}
public void setHeight(double heightIn){
height = heightIn;
}
}
public class WeightInApp{
public static void main (String [] args){
WeightIn weight1 = new WeightIn(); //Error happens here.
weight1.setWeight(3.65);
weight2.setHeight(1.7);
}
}
我定义了一个构造函数。
原文由 user2669883 发布,翻译遵循 CC BY-SA 4.0 许可协议
将此添加到您的班级: