为什么我使用这种抽象方法会出错?

时间:2012-12-05 14:17:57

标签: java

我在使用此代码时遇到以下错误:

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

为什么我收到此错误?

2 个答案:

答案 0 :(得分:1)

CheckBalanceBankingServant中的_BankingImplBase方法可能有不同的签名。看起来它们具有相同的参数,因此它可能具有不同的返回类型。

答案 1 :(得分:1)

你有

private int CheckBalance;

public void CheckBalance(String accName) {

您可以遵循两种Java约定来阻止这样的事情:

  1. 始终使用小写字母开始方法和字段名称。
  2. 在这个例子中更重要字段应该被赋予名词名称,方法应该被赋予动词名称,所以他们几乎从不拥有同名。
  3. 您可以在此处找到有关命名约定的一些很好的参考资料: