next up previous
Next: 1.3.2 Constructors Up: 1.3 Java Class Definitions Previous: 1.3 Java Class Definitions


1.3.1 Defining Classes to Represent Compound Data

We have finally introduced enough Java mechanics to define the data required to represent the department directory entries described in Section 1.1.2. Recall that a directory entry is a object with the following fields and methods:

Fields:
    String name;
    String address;
    String phone;
	
Methods:
    String getName();
    String getAddress();
    String getPhone();
In Java, we define this new form of data as the class
class Entry {
  /* fields */
  String name;	
  String address;
  String phone;

  /* accessors */
  String getName() { return this.name; }
  String getAddress() { return this.address; }
  String getPhone() { return this.phone; }
}



Corky Cartwright 2003-07-07