Java Reference
In-Depth Information
return values. Simply run javadoc on your file to generate the documentation for
the public interface that you are about to implement.
The javadoc tool is wonderful because it does one thing right: It allows you to
put the documentation together with your code. That way, when you update your
programs, you can see right away which documentation needs to be updated.
Hopefully, you will update it right then and there. Afterward, run javadoc again
and get updated information that is timely and nicely formatted.
3.4 Instance Fields
Now that you understand the specification of the public interface of the
BankAccount class, let's provide the implementation.
First, we need to determine the data that each bank account object contains. In the
case of our simple bank account class, each object needs to store a single value, the
current balance. (A more complex bank account class might store additional dataȌ
perhaps an account number, the interest rate paid, the date for mailing out the next
statement, and so on.)
An object stores its data in instance fields. A field is a technical term for a storage
location inside a block of memory. An instance of a class is an object of the class.
Thus, an instance field is a storage location that is present in each object of the class.
An object uses instance fields to store its stateȌthe data that it needs to execute its
methods.
The class declaration specifies the instance fields:
public class BankAccount
{
. . .
private double balance;
}
93
Search WWH ::




Custom Search