gpt4 book ai didi

java - 编译器无法正确识别构造函数重写

转载 作者:行者123 更新时间:2023-12-02 11:20:13 26 4
gpt4 key购买 nike

我会让代码和错误来说话,因为我真的认为他们说了一切,除了这不应该发生!有人知道如何编译这个吗?

代码

<小时/>
  class CountDownTimerGUI extends BHTimerGUI
{
private TimerJPanel control;
private TimerDisplayJPanel disp;

public CountDownTimerGUI(TimerJPanel control, TimerDisplayJPanel disp)
>> {
this.control = control;
this.disp = disp;
}
}

(>>表示错误行)

这会覆盖 BHTimerGUI 的构造函数,其构造函数如下:

  public BHTimerGUI(TimerJPanel control, TimerDisplayJPanel disp)
{
this.control = control;
this.disp = disp;
}

编译器错误

<小时/>
I:\Java\NetBeansProjects\Blue Husky's Timer 2.0.0\src\bhtimer\GUI.java:145: cannot find symbol
symbol : constructor BHTimerGUI()
location: class bhtimer.BHTimerGUI
{

NetBeans 显示一个包含以下文本的弹出窗口:

constructor BHTimerGUI in class bhtimer.BHTimerGUI cannot be applied to given types;
required: bhtimer.TimerJPanel,bhtimer.TimerDisplayJPanel
found: no arguments
reason: actual and formal argument lists differ in length

最佳答案

是的,这应该发生!您没有初始化父类(super class)构造函数。尝试使用这个构造函数:

   public CountDownTimerGUI(TimerJPanel control, TimerDisplayJPanel disp){
super(control, disp);
this.control = control;
this.disp = disp;
}

关于java - 编译器无法正确识别构造函数重写,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6245453/

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