... otherwise, it appears as a value from 1 to 11. The conditional operator in line 33 determines whether AM or PM will be returned as part of the String
.
Recall that all objects in Java have a toString
method that returns a String
representation of the object. We chose to return a String
containing the time in standard-time format. Method toString
is called implicitly whenever a Time1
object appears in the code where a String
is needed, such as the value to output with a %s
format specifier in a call to System.out.printf
. You may also call toString
explicitly to obtain a String
representation of a Time
object.
Using Class Time1
Class Time1Test
(Fig. 8.2) uses class Time1
. Line 7 declares the Time1
variable time
and initializes it with a new Time1
object. ...
Get Java How To Program, Late Objects, 11th 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.