Referencing Interfaces

You have learned how to create interfaces and build classes based on interfaces. However, interfaces are not useful unless you can develop classes that will either employ the derived classes or the interface itself.

Accessing Constants

Although the fields of an interface must be both static and final, they can be extremely useful in your code.

The following example demonstrates that any constant from an interface can be referenced using the same dot notation you use with classes. This means that you can use constants from your own interfaces or those in the Java API such as java.awt.image.ImageConsumer.COMPLETESCANLINES and java.awt.Event.MOUSE_DOWN in your code. Listing 9.7 shows an example of another ImageConsumer field ...

Get Special Edition Using Java 2 Standard 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.