Interfaces

Interfaces are reference types like classes, but can have only abstract method declarations and constants as members. Interfaces are defined in the same way as classes, with a source code file that has a .java file type that is compiled to a class file. Interfaces are also members of packages, just like classes. Java uses interfaces extensively to provide a convenient alternative to multiple inheritance. A Java class can implement any number of interfaces.

A class that implements an interface must provide implementations for all the methods that the interface defines. An object of this class then has a sort of alternative identity and can be referred to as being of the interface type. For example, the Runnable interface, a member of ...

Get Java 2™ Programmer Exam Cram™ 2 (Exam CX-310-035) 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.