Review of ==

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

Answer:

  • How many CheckingAccount objects are there?   Two
  • How many object reference variables are there?   Three
  • What will the program print out?
123     Bob     100
456     Jill    900
123     Bob     100

Review of ==

The == (equal-equal) operator is an alias detector. It checks if two reference variables refer to the same object. It does not actually look at the objects. The following program segment illustrates this:

  {
    CheckingAccount account1 = new CheckingAccount( "123", "Bob", 100 );
    CheckingAccount account2 = new CheckingAccount( "456", "Jill", 900 );
    CheckingAccount account3; 
    
    account3 = account1;
    if ( account1 == account 3 )
       System.out.println("An alias has been detected!");
    else
       System.out.println("These are different objects!");
   
  }

It will print out An alias has been detected!.

QUESTION 22:

Say that the following lines are added to the program (immediately following the lines already there):

    account3.processCheck( 85 );  // subtract 100 cents, including service charge
    account1.display();
    account3.display();

What will be printed?