[英]Cannot find symbol error
I am writing some code that extends another class I developed for a programming assignment.我正在编写一些代码来扩展我为编程任务开发的另一个 class。 However I keep getting stuck with one single error when I try to compile my program:
但是,当我尝试编译我的程序时,我总是遇到一个错误:
CDAccount.java:11: cannot find symbol
symbol : constructor BankAccount()
location: class BankAccount
{
^
And the program is as follows:程序如下:
import java.lang.IllegalArgumentException;
public class CDAccount extends BankAccount
{
Person owner_;
double balance_;
double rate_;
double penalty_;
public CDAccount(Person Owner, double Balance, double Rate, double Penalty)
{
if(Balance < 0)
{
throw new IllegalArgumentException("Please enter a positive Balance amount");
}
else
{
if(Rate < 0)
{
throw new IllegalArgumentException("Please enter a positive Interest Rate");
}
else
{
if(Penalty < 0)
{
throw new IllegalArgumentException("Please enter a positive Penalty amount");
}
else
{
if(Owner.equals(null))
{
throw new IllegalArgumentException("Please define the Person");
}
else
{
owner_ = Owner;
balance_ = Balance;
rate_ = Rate;
penalty_ = Penalty;
}
}
}
}
}
}
Your CDAccount constructor neesd to call the super class constructor as it's first statement.您的 CDAccount 构造函数需要调用超级 class 构造函数,因为它是第一条语句。 If you don't explicitly put
如果您没有明确提出
super();
as the first line, then the compiler will insert作为第一行,编译器将插入
super();
for you (invisibly).为你(无形)。
However your BackAccount class apparently doesn't have a constructor that takes no parameters, so either add a constructor that does, or explicitly add a call to the super class with parameters that you have a constructor for like但是,您的 BackAccount class 显然没有不带参数的构造函数,因此要么添加不带参数的构造函数,要么显式添加对超级 class 的调用,并带有参数,您有类似的构造函数
super(owner);
or whatever you want to pass to the super class.或者任何你想传递给超级 class 的东西。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.