Demonstration: how to return a String object.
In the MobilePhone class for example,
suppose we have the following method
public void printCreditsLeft()
{
System.out.printf( "Credits left: P%4.2f\n", creditsLeft );
}
If x is a MobilePhone object,
x.printCreditsLeft(); will print the number of credits left.
Another way to carry this out is to have the following method instead:
public String howMuchCreditsLeft()
{
String temp = String.format( "Credits left: P%4.2f", creditsLeft );
return temp;
}
and the caller would issue:
System.out.println( x.howMuchCreditsLeft() );