CallByValueDemo.java.html

  1  public class CallByValueDemo
  2  {
  3     public static void main(String[] args)
  4     {
  5        BankAccount harrysChecking = new BankAccount(2500);
  6        double savingsBalance = 1000;
  7        System.out.println("Before: " + savingsBalance);
  8        harrysChecking.transfer(500, savingsBalance); 
  9        System.out.println("After: " + savingsBalance);
 10        
 11        BankAccount harrysSavings = new BankAccount(1000);
 12        System.out.println("Before: " + harrysSavings.getBalance());
 13        harrysChecking.transfer(500, harrysSavings);  
 14        System.out.println("After: " + harrysSavings.getBalance());
 15        
 16        BankAccount savingsAccount = new BankAccount(1000);
 17        System.out.println("Before: " + savingsAccount.getBalance());
 18        harrysChecking.transfer2(500, savingsAccount);  
 19        System.out.println("After: " + savingsAccount.getBalance());
 20     }
 21  }