No, the balance of account1 is private and can't be accessed outside of the object.
toString()
All objects automatically have a toString() method
that creates a String for the object and returns a reference to it.
The compiler puts in a toString() method even if you did not write it.
This mechanism is called inheritance and is the subject of a upcoming chapter.
If you explicitly put your own toString() method
in a class, that one will be used instead of the inherited method.
The method you write must start with the method header
public String toString()
The reserved word public must be there.
The chapter on inheritance will explain this further.
Fill in the blanks below to complete the method.
class CheckingAccount
{
// instance variables
private String accountNumber;
private String accountHolder;
private int balance;
//constructors
. . . .
// methods
. . . .
public String toString()
{
return "Account: " + + ";\tOwner: " + ";\tBalance: " + ;
}
}
Fill in the blanks. The "\t" in the strings represents the tab character.