Aliases

  1. Two object variables are aliases if they refer to the same object

    Example:

    MyVariable is an alias of harrysChecking (and vice versa).

  2. How are aliases created:


    Example:
       BankAccount harrysChecking = new BankAccount();
       BankAccount momsSaving = new BankAccount();
       BankAccount myVariable;
    
       myVariable = harrysChecking;   // Create alias
    

  3. Effect of using an alias:


    Example:
      myVariable.deposit(1000);   // adds 1000 to harrysChecking.balance !
    
  4. DEMO programs