O'Reilly logo

Java™ How to Program, Seventh Edition by P. J. Deitel - Deitel & Associates, Inc., H. M. Deitel - Deitel & Associates, Inc.

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

8.2. Time Class Case Study

Time1 Class Declaration

Our first example consists of two classes—Time1 (Fig. 8.1) and Time1Test (Fig. 8.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 are both public classes. The output of this program appears in Fig. 8.2.

Figure 8.1. Time1 class declaration maintains the time in 24-hour format.
 1 // Fig. 8.1: Time1.java
 2 // Time1 class declaration maintains the time in 24-hour format.
 3
 4 public class Time1
 5 {
 6    private int hour;   // 0 - 23
 7    private int minute; // 0 - 59
 8    private int second; // 0 - 59
 9
10    // set a new time value ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required