next up previous
Next: 1.9.1 Multiple Inheritance Up: 1. From Scheme to Previous: 1.8.5 Conclusion

1.9 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 lightweight form of 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 the corresponding 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.

In this monograph, we will follow the convention that interface names begin with ``I'' followed by a capitalized name. Hence, ``IList'' is the name of an interface, while ``List'' is the name of a class. There is no generally accepted convention for distinguishing interface names from class names in the Java programming culture. In the Java libraries, for example, there is no way to tell a class from an interface based on its name.

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.11.



Subsections
next up previous
Next: 1.9.1 Multiple Inheritance Up: 1. From Scheme to Previous: 1.8.5 Conclusion
Corky Cartwright 2002-08-09