Using Class Time1

Class Time1Test (Fig. 8.2) uses class Time1. Line 9 declares and creates a Time1 object time. Operator new implicitly invokes class Time1’s default constructor, because Time1 does not declare any constructors. To confirm that the Time1 object was initialized properly, line 12 calls the private method displayTime (lines 35–39), which, in turn, calls the Time1 object’s toUniversalString and toString methods to output the time in universal-time format and standard-time format, respectively. Note that toString could have been called implicitly here rather than explicitly. Next, line 16 invokes method setTime of the time object to change the time. Then line 17 calls displayTime again to output the time in both formats to confirm ...

Get Java™ How To Program (Early Objects), Tenth Edition 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.