What Are Interfaces?

A Java interface is a set of constants and method declarations without an implementation, as shown in Listing 9.1.

Code Listing 9.1. Steerable.java—An Interface for Steerable Vehicles
public interface Steerable {

  String NORTH_DIRECTION = "North";
  String SOUTH_DIRECTION = "South";
  String EAST_DIRECTION  = "East";
  String WEST_DIRECTION  = "West";

  void turnLeft();
  void turnRight();
  String getCurrentDirection();
}

This concept might not sound too impressive at this point, but interfaces are a powerful feature of the Java language. Successful object-oriented programming depends on separating the functionality needed by one part of your system from how that functionality is ultimately implemented by another part. Interfaces are ...

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.