Device states
We consider an enum
describing device
states:
Device state enumeration | Main method | Result |
---|---|---|
|
|
Hello! Hello! Hello! |
Answer the following questions:
-
The
Device()
constructor is being declaredprivate
so how does it get invoked at all? -
Why do we see
"Hello!"
three times on output though onlyDevice.STANDBY
shows up in the current example'smain(...)
method?
Solution
ON
, OFF
and STANDBY
are static references to
Device
instances being created inside our enum
Device
class. This
happens the way being described in Figure 368, “Define a private
Day
constructor ”.
Thus our private constructor in question is being called from
within enum
Device
class scope and therefore not being limited by access
restrictions.