F.2 Time Class Case Study

Our first example consists of two classes—Time1 (Fig. F.1) and Time1Test (Fig. F.2). Class Time1 represents the time of day. Class Time1Test is an application class in which the main method creates one object of class Time1 and invokes its methods. These classes must be declared in separate files because they’re both public classes. The output of this program appears in Fig. F.2.

Fig. F.1 Time1 class declaration maintains the time in 24-hour format

Computer code has 40 lines.

Fig. F.2 Time1 object used in an application

Time1 Class Declaration

Class Time1’s private int instance ...

Get Android How to Program, 3/e now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.