next up previous
Next: 1.8.1 Multiple Inheritance Up: 1. From Scheme to Previous: 1.7 Using Classes to

1.8 Interfaces

We have not yet discussed one of most important object-oriented features of Java, namely the notion of an interface. In essence, an interface is a special form of lightweight abstract class. We use the term lightweight to describe an abstract class with no fields and no concrete methods; the only members are abstract methods. The key difference between an interface and a conventional abstract class is that a class or interface can have unlimited number of immediate superinterfaces but it can only have one superclass.

An interface definition has almost the same syntax as a class definition:

interface name {

... member declarations ...
}
The only significant difference is the keyword interface instead of class.

A class can implement an arbitrary number of interfaces. A class definition can optionally include an implements clause immediately following the extends clause (assuming one is present) in the class header. Sample programs using interfaces appear in 1.9.



 

Corky Cartwright
2000-01-07