0

我收到以下代码错误:

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: ");
  }
}

为什么我会收到此错误?

4

2 回答 2

1

您的CheckBalance方法很可能具有不同的签名。看起来它们具有相同的参数,因此它可能具有不同的返回类型。BankingServant_BankingImplBase

于 2012-12-05T14:20:58.163 回答
1

你有

private int CheckBalance;

public void CheckBalance(String accName) {

您可以遵循两个 Java 约定来防止发生这样的事情:

  1. 始终以小写字母开头的方法和字段名称。
  2. 在这个例子中更重要的是字段应该被赋予名词名称,方法应该被赋予动词名称,因此它们几乎不应该具有相同的名称。

您可以在此处找到有关命名约定的一些很好的参考:

于 2012-12-05T14:26:49.933 回答