gpt4 book ai didi

java - 为什么我使用这个抽象方法会出错?

转载 作者:行者123 更新时间:2023-12-02 07:24:34 26 4
gpt4 key购买 nike

我使用此代码收到以下错误:

BankingServant is not abstract and does not override abstract method
CheckBalance(String) in BankingOperations public class BankingServant
extends _BankingImplBase

这是我的代码:

import BankingApp._BankingImplBase;
import BankingApp.*;
import java.util.ArrayList;
import java.util.Iterator;

public class BankingServant extends _BankingImplBase {
private int AccountName;
private int LodgementAmount ;
private int TransferAmount ;
private int WithdrawlAmount;
private int TransferAmount;
private int TransferAccWith;
private int TransferAccDep;
private int CheckBalance;

private class Account {
String accName;
}

private class Trans {
String accName;
double transferAmount;
double transferAccWith;
double transferAccDep;
double withAmount;
double lodgementAmount;
}

private class With {
String accName;
double withAmount;
}

public boolean Lodgement(String accName, double lodgementAmount) {
System.out.println("Enter Lodgement.");
Account acc = new Account();
acc.accName = accName;
acc.lodgementAmount = lodgementAmount;
acc.add(acc);
System.out.println("Money was lodged.");
}

public boolean Transfer(String accName, double transferAmount, double transferAccWith, double transferAccDep){
System.out.println("Transfer Amount: ");
Trans bankingTemp = new Trans();
bankingTemp.accName = accName;
bankingTemp.transferAmount = transferAmount;
bankingTemp.transferAccWith = transferAccWith;
bankingTemp.transferAccDep = transferAccDep;
bankingTemp.parts = this.parts;
bankingTemp.planeId = planeId;
banking.add(bankingTemp);
System.out.println("Transfered");
planeId++;
return true;
}

public void CheckBalance(String accName) {
System.out.println("Balance is: ");
Account accB = new Account();
accB.accName = accName;
accB.checkBalance = checkBalance;
accB.add(accB);
System.out.println("Balance is: ");
}
}

为什么我会收到此错误?

最佳答案

你有

private int CheckBalance;

public void CheckBalance(String accName) {

您可以遵循两个 Java 约定来防止出现此类情况:

  1. 方法和字段名称始终以小写字母开头。
  2. 在这个例子中更重要字段应该给出名词名称,方法应该给出动词名称,所以它们几乎不应该有同名。

您可以在这里找到一些有关命名约定的好引用:

关于java - 为什么我使用这个抽象方法会出错?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13725241/

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