In Section 1.2, we introduced a class definition for department directory entries and briefly explained its various parts. We will now review the syntactic structure and semantic behavior of classes in more detail.
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 can express the data definition by 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; } }
But this class definition is not complete because it does not define a suitable constructor for creating and initializing objects of this form.