2.4 Example: Definition of the class Author
/*
+-------------+
| Author |
+-------------+
| String name |
| int dob |
+-------------+
*/
// to represent an author of a book
class Author {
String name;
int dob;
Author(String name, int dob) {
this.name = name;
this.dob = dob;
}
}
/*Interactions:
Examples of the use of the constructor
Author mf = new Author("Matthias", 1900);
Author pc = new Author("Pat Conroy", 1940);
Author eap = new Author("Annie", 1046);
Examples of the use of the field selectors for the class Author
mf.name -- expected: "Matthias"
mf.dob -- expected: 1900
pc.name -- expected: "Pat Conroy"
pc.dob -- expected: 1940
*/