|
|
More Features of the Java Language |
When you define a new interface, you are in essence defining a new reference data type. You can use interface names anywhere you can use any other data type name.For example, the
AlarmClockclass uses theSleepertype in two places:
- To declare an array of
Sleepers (shown in bold):private Sleeper[] sleepers = new Sleeper[MAX_CAPACITY];- As an argument to
letMeSleepFor(shown in bold):private boolean letMeSleepFor(SleepertheSleeper, int time) { . . . }
|
|
More Features of the Java Language |