[an error occurred while processing this directive] In these examples we will define two classes of objects, bank customers (class Customer) and bank accounts (class Account). We will slowly build these classes by adding different components. At each step , the name of the classes will increase by 1, starting with Account1 and Customer1. Starting with the third step, you can run a banking application which demonstrated the new features in that step.

  1. Instance variables specify the properties of the objects.
    See the variables in Customer1.java and Account1.java

  2. Instance methods specify the behaviour of the objects.
    See the methods in Customer2.java and Account2.java

  3. Constructor methods are used to specify how the class is instantiated, i.e. how new objects of that class are created. Constructor methods have the same name as the class.
    See Customer3.java , Account3.java and Banking3.java.
    In this example, one customer is created with one account. Then the account is manipulated.

  4. However, one can create multiple instances of the same class.
    See Customer4.java , Account4.java and Banking4.java.
    In this example, each object responds to requests for information send via the WhoAmI method.

  5. Class variables are used to keep information that is meant to be shared by all instances of the class.
    See Account5.java and Banking5.java. There is no change to the Customer class in this example, so Customer4.java is used.
    In this example, the class variable accountID has been added to the Account class to generate different account IDs to each account.

  6. Class variables can also be public, when information belongs to a class but is meant to be easily shared outside.
    In Account6.java and Banking6.java. the credit ratings are defined in the Customer6.java class because they belong to customers.

  7. Classes can have multiple constructors, all with the same names, but with different parameter structures.
    In Customer7.java the class Customer7 has multiple constructors to deal with various situations.
    This is demonstrated in the Banking7.java. program.
    When a method has multiple definitions, this is called method overloading.

  8. Methods can also be associated with entire classes instead of with objects in the class. These are called class methods.
    In the following examples, a new class method to send messages to all objects in one class is added.


This page is maintained by Sophie Quigley, e-mail: quigley@torontomu.ca
Last modified Friday, 26-Sep-2003 00:09:15 EDT