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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access