The Department of Computer Science & Engineering
cse@buffalo
STUART C. SHAPIRO: CSE 115 C

CSE 115
Introduction To Computer Science for Majors I
Lecture C
Lecture Notes
Stuart C. Shapiro
Spring, 2001


Interfaces

Reading
Brown U. Notes, Chapter 6

To replace multiple inheritance, although a Java class may only extend one superclass, it may implement any number of interfaces.

An interface is similar to an abstract class, but contains no instance variables, nor constructors, only abstract methods.
These methods are assumed to be abstract and public---no need to say so explicitly.

An interface may extend any number of other interfaces.

A class that implements an interface must define all it's methods, or be abstract.

An interface may be used to type a variable or a method.
A variable typed as an interface may be given as value any instance of any class that implements that interface.

See the Interface demonstration.

First Previous Next

Copyright © 2001 by Stuart C. Shapiro. All rights reserved.

Stuart C. Shapiro <shapiro@cse.buffalo.edu>