⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bankaccount.java

📁 Java 入门书的源码
💻 JAVA
字号:
//Copyright (c) 1998, Arthur Gittleman
//This example is provided WITHOUT ANY WARRANTY either expressed or implied.

/* Declare a BankAccount class with an account balance 
 * attribute, a constructor, and deposit and getBalance
 *  operations.  Create and use some BankAccount objects.
 */

public class BankAccount {
  private int balance;
  BankAccount()   {    
    balance = 0;
  }
  public void deposit(int amount) {
    balance += amount;
  }
  public int getBalance() {
    return balance;
  }
  public static void main (String [ ] args) {
    BankAccount myAccount = new BankAccount();
    System.out.println("My balance = " + myAccount.getBalance());
    myAccount.deposit(10000);
    System.out.println("My balance = " + myAccount.getBalance());
    BankAccount  yourAccount;
    yourAccount = new BankAccount();
    yourAccount.deposit(123456);
    System.out.println("Your balance = " + yourAccount.getBalance());
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -