Using Class Time1
As you learned in Appendix B, each class you declare represents a new type in Java. Therefore, after declaring class Time1
, we can use it as a type in declarations such as
Time1 sunset; // sunset can hold a reference to a Time1 object
The Time1Test
application class (Fig. F.2) uses class Time1
. Line 9 declares and creates a Time1
object and assigns it to local variable time
. Operator new
implicitly invokes class Time1
’s default constructor, since Time1
does not declare any constructors. Lines 12–16 output the time first in universal-time format (by invoking time
’s toUniversalString
method in line 13), then in standard-time format (by explicitly invoking time
’s toString
method in line 15) to confirm ...
Get Android™ How to Program, Second 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.