Lecture 6: Creating & Using Java Classes

This lecture explores how the concepts discussed in the previous lecture are realised in Java. It starts from a UML diagram describing a class, and shows how the different elements of this class can be built up piece by piece – starting with private fields, then moving on to implement constructors that create instances of the class, then public getter methods for the fields, then setter methods. The lecture considers the issue of whether setters should be private, making objects of the class immutable, or whether they should be public, allowing changes of object state. The lecture finishes with a look at other features of the class, such as the equals() and toString() methods.

Useful resources: