这是银行帐户类别:
namespace BankAccount
{
public abstract class BankAccount
{
protected static int numberOfAccounts = 100001;
private double balance;
private string owner;
private string accountNumber;
public BankAccount()
{
balance = 0;
accountNumber = numberOfAccounts + "";
numberOfAccounts++;
}
public BankAccount(string name, double amount)
{
owner = name;
balance = amount;
accountNumber = numberOfAccounts + "";
numberOfAccounts++;
}
public BankAccount(BankAccount oldAccount, double amount)
{
owner = oldAccount.owner;
balance = amount;
accountNumber = oldAccount.accountNumber;
}
}
}
这是支票帐户类别:
namespace BankAccount
{
class CheckingAccount : BankAccount
{
int fee = 15;
public CheckingAccount(string name, double amount)
{
base.BankAccount(name, amount);
}
public new bool Withdraw(double amount)
{
double totalAmount = amount + fee;
return base.Withdraw(totalAmount);
}
}
}
对于base.BankAccount(name, amount);
,我收到了错误消息
“银行帐户”不包含“银行帐户”的定义。
银行帐户是基类,而支票帐户继承基类。当我删除基本关键字时,它说:
非可调用成员不能用作方法。
在主体中,我创建了一个对象,我要在Main中接受一个值-字符串和双精度型,然后将其发送到CheckingAccount
类,并且CheckingAccount
构造函数应运行然后发送值BankAccount
构造函数并进行计算。
如何解决错误
“银行帐户”不包含“银行帐户”的定义
。 ? 谢谢,
答案 0 :(得分:1)
C#与Java不同,在花括号之间调用super()时,需要添加':base(name,Amout)'来调用超类构造函数。像这样:
updateText()
答案 1 :(得分:0)
您可以通过这种方式调用它。
public CheckingAccount(string name, double amount) : base (name, amount)
{
}