Before discussing the specifics of Java's object system, let's define what an object is. Within a computer program, an object consists of
To make the notion of object more concrete, let's consider a simple example. Assume that we want to write an simple accounting program for a snack food cooperative run by graduate students. (Such a cooperative actually exists in Duncan Hall at Rice.) Every participant in the cooperative has an account.
A minimal accounting system could define an object to represent each account. Each such ``account'' object would consist of an integer field balance holding the balance for that account (in cents) and two void operations: charge(integer amt) which subtracts amt from the account balance and deposit(integer amt) which adds amt to the account.
Members of the cooperative can either deposit money in their accounts or purchase items by charging their accounts. You may have seen a similar example in Scheme in Comp 210.
Let's summarize the form of an account object as a table:
Fields:
integer balance
Methods:
void charge(integer amt)
void deposit(integer amt)
This tabular description is NOT legal Java syntax, although
it uses the Java keyword void.
We will
introduce the actual syntactic details later in our discussion.