Class Time2’s Constructors
Lines 12–15 declare a so-called no-argument constructor that’s invoked without arguments. Once you declare any constructors in a class, the compiler will not provide a default constructor. This no-argument constructor ensures that class Time2
’s clients can create Time2
objects with default values. Such a constructor simply initializes the object as specified in the constructor’s body. In the body, we introduce a use of the this
reference that’s allowed only as the first statement in a constructor’s body. Line 14 uses this
in method-call syntax to invoke the Time2
constructor that takes three parameters (lines 30–33) with values of 0 for the hour
, minute
and second
. Using the this
reference as shown here is a popular ...
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.