Declaring Interfaces

An interface defines a collection of methods that is implemented by a class. However, it can also be used to define constants, inner classes, and inner interfaces. The syntax of an interface declaration is as follows:

modifiers interface InterfaceName extendsClause {
 // Interface body
}

An interface can use the modifiers public and abstract. However, the abstract modifier is redundant and should not be used—all interfaces are abstract because they only declare abstract methods. An interface that is declared as public can only be accessed outside its package.

The extends clause consists of the keyword extends followed by a comma-separated list of the interfaces that are extended. An extending interface inherits all the constants ...

Get Sun Certification Training Guide (310-025, 310-027): Java™ 2 Programmer and Developer Exams 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.