/* オーバーロードの例 */ class BankAccount { private String name; // 名前 private int number; // 口座番号 private int balance; // 残高 public BankAccount (String name, int number) { this.name = name; // フィールドnameに引数nameを代入 this.number = number; this.balance = 0; } private void deposit (int amount) { balance += amount; // 実際に預金するメソッド } public void deposit (int amount, String name) { if (name.equals(this.name)) { // 名前が一致したら deposit(amount); // 預金手続きをする } } public void deposit (int amount, int number) { if (this.number == number) { // 口座番号が一致したら deposit(amount); // 預金手続きをする } } public static void main (String[] args) { BankAccount b1 = new BankAccount("Taro", 1234567); b1.deposit(10000, "Taro"); // 預金者名で確認してから預金する b1.deposit(3000, 1234567); // 口座番号で確認してから預金する System.out.println(b1.balance); // 13000 } }