gpt4 book ai didi

java - 找不到符号 Java

转载 作者:行者123 更新时间:2023-12-01 15:14:03 26 4
gpt4 key购买 nike

我正在为我的类(class)做一个练习,我在编码过程中偶然发现了一个问题。我应该创建一个扩展类,我认为我遇到的问题是我为构造函数提供的参数。

这是直接父类(super class):

public class ElectricalComponent extends Component 
{
private int myMinRating,
myMaxRating;

public ElectricalComponent( String partNumber, int versionNumber, int minRating, int maxRating )
{
super( "Electrical", partNumber, versionNumber );
myMinRating = minRating;
myMaxRating = maxRating;
}

public int getMinRating() { return myMinRating; }
public int getMaxRating() { return myMaxRating; }
}

这是我正在学习的类(class):

public class HighvoltageComponent extends ElectricalComponent
{
private int myMinRating, myMaxRating;

public HighvoltageComponent( String partNumber, int versionNumber)
{
super( "Electrical", partNumber, versionNumber );
myMinRating = 50000;
myMaxRating = 200000;
}

}

我的问题出在子类中:“HighVoltageComponent ( String ... )”

当我运行主类时

public static void main( String[] args )
{
// test your code here
Component a = new HighvoltageComponent( "HV12", 0 );

System.out.println( a.toString() );
System.out.println( a.getTypeName() );
System.out.println( a.getPartNumber() );
System.out.println( a.getVersionNumber() );
}

我收到错误消息

"HighvoltageComponent.java:9: cannot find symbol

symbol : constructor ElectricalComponent(java.lang.String,java.lang.String,int) "

为什么会发生这种情况?

另外,您能告诉我我做这个问题的方法是否正确吗?这是问题:

A HighvoltageComponent is an ElectricalComponent with a minimum rating of 50000 and a maximum rating of 200000. Complete the following definition of HighvoltageComponent. (You will need to insert code at more than one place in the code area below.)

谢谢,罗汉

最佳答案

ElectricalComponent 构造函数需要四个参数,您在 HighVoltageComponent 中的调用 super( "Electrical", partNumber, versionNumber ); 中仅传递了三个参数类

你的 super 调用应该是这样的

super( partNumber, versionNumber,myMinRating ,myMaxRating );

关于java - 找不到符号 Java,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11894871/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com