Creating and Extending Interfaces

After you use interfaces for a while, the next step is to define your own interfaces. Interfaces look a lot like classes; they are declared in much the same way and can be arranged into a hierarchy. However, you must follow certain rules for declaring interfaces.

New Interfaces

To create a new interface, you declare it like this:

interface Growable { 
    // ...
}

This declaration is, effectively, the same as a class definition, with the word interface replacing the word class. Inside the interface definition, you have methods and constants. The method definitions inside the interface are public and abstract methods; you can either declare them explicitly as such, or they are turned into public and abstract methods ...

Get Sams Teach Yourself Java 2 in 21 Days, 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.