Interfaces

Interfaces form an alternative to having multiple inheritance. A class can inherit from only one superclass, but may implement several interfaces. Java thus has single inheritance of implementation but multiple inheritance of definition.

An interface may extend another interface.


Example:
interface Debugging {
    void setDebug(boolean on);
    boolean Debug();
}

class Rectangle implements Debugging {
    private boolean debugmode = false;
    void setDebug(boolean on) {
        debugmode = on;
    }
    boolean Debug() {
        return debugmode;
    }
    // ...
}