withdraw.java

来自「Java 入门书的源码」· Java 代码 · 共 27 行

JAVA
27
字号
//Copyright (c) 1998, Arthur Gittleman
//This example is provided WITHOUT ANY WARRANTY either expressed or implied.

/*  Uses the withdraw operation of
 *  BankAccount and its subclasses
 *  to illustrate polymorphism
 */

import iopack.Io;
public class Withdraw {
  public static void main(String [] args) {
    BankAccount b1 = new CheckingAccount(1500.00,.50);
    BankAccount b2 = new SavingsAccount(500.00, 4.0);
    b1.deposit(400.00);
    b1.withdraw(50.00);
    System.out.print("The balance of the BankAccount to which b1 refers is ");  
    Io.println$(b1.getBalance());
    b2.withdraw(50.00);
    System.out.print("The balance of the BankAccount to which b2 refers is ");  
    Io.println$(b2.getBalance());
    b2 = b1;
    b2.withdraw(50.00); 
    System.out.print("The balance of the BankAccount to which b2 refers is ");  
    Io.println$(b2.getBalance());
  }
}

⌨️ 快捷键说明

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