Account: 123; Owner: Bob; Balance: 100 Account: 456; Owner: Jill; Balance: 900 Account: 123; Owner: Bob; Balance: 100
==
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!.
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
System.out.println( account1.toString() );
System.out.println( account3.toString() );
What will these lines print?