public String toString()
{
return "Account: " + accountNumber + ";\tOwner: " + accountHolder + ";\tBalance: " + balance ;
}
toString() Method
Since toString() is a member of a CheckingAccount object,
the object's data is accessed by using the variable name,
like accountNumber.
class CheckingAccount
{
. . . . (Now including the toString() method.)
}
public class CheckingAccountTester
{
public static void main( String[] args )
{
CheckingAccount account1 = new CheckingAccount( "123", "Bob", 100 );
System.out.println( account1.toString() );
}
}
The output is now:
Account: 123; Owner: Bob; Balance: 100
With this nice new method in place, you must surely be eager to do further testing of the program. Add statements in the box so that the output is:
Account: 123; Owner: Bob; Balance: 100 Account: 007; Owner: James; Balance: 45723