Aliasing (Review)

Classic programmed-learning exercises, refreshed for modern Java and presented in the current MrStyner.com portfolio style.

Modern Java noteThis archive has been refreshed for Java 25 LTS. Core language concepts remain useful, while outdated setup instructions and browser-era Java are labeled or replaced. Java 26 is the current feature release; Java 25 is used here as the stable teaching baseline.
go to previous page   go to home page   go to next page

Say that James wrote out a $300 check to Bob, and that Bob deposited the check in Bob's account.

Answer:

  public static void main( String[] args )
  {
     . . . . . .
    
    int check = 30000;
    account2.processCheck( check );
    account1.processDeposit( check );
    account1.display();
    account2.display();
    
  }

Aliasing (Review)

This is not really part of testing this class, but it is convenient to mention aliasing again. Recall that there can be more than one reference to a given object. Each reference is called an alias. Here is another test program, set up to show this:

class CheckingAccount
{
  . . . . 
}

class CheckingAccountTester
{
  public static void main( String[] args )
  {
    CheckingAccount account1 = new CheckingAccount( "123", "Bob", 100 );
    CheckingAccount account2 = new CheckingAccount( "456", "Jill", 900 );
    CheckingAccount account3; 
    
    account1.display() ;
    account2.display() ;

    account3 = account1;
    account3.display() ;
  }
}

QUESTION 21:

  • How many CheckingAccount objects are there?
  • How many object reference variables are there?
  • What will the program print out?