SUmmary of Class Presentation for June 24, 1999 Topics: Interfaces Java provides a feature that supports the advantages of multiple inheritance without most of the disadvantages. This feature is the interface. An interface is defined by: interface name { constants variables method headers } All the declared variables are automatically final and static. All the methods are automatically public. There is no code in an interface. Classes can implement an interface by class sample implements interfacea { ... } Implementing an interface provides a class with all the constants and variables defined within that interface and obligates the class to implement all the methods whose headers appear in the interface. Classes may implement more than one interface: class sample implements interfacea, interfaceb, interfacec { } Interfaces specify types as do classes. On the previous line, sample specifies a sample type and objects of class sample are members of that type. Objects of class sample are also members of the interfacea, interfaceb, and interfacec types. As many classes as you wish may implement an interface and all of their objects would be members of that interface type. In nearly all cases, you can think of a class as having an associated type. There are two differences between classes and types: 1. Interfaces also have associated types 2. Even though objects of a derived class are members of the type associated with their base class, the dervied class objects do not get access to private fields within the base class while all the objects of the base class do. You may declare interface variables, but there are no interface objects. Instead, you may assign an object of any class that implements the interface to any interface variable or anywhere an interface value is required ( such as when the return type of a method is declared to be an interface or when a parameter is declared to be of an interface type). Interfaces can inherit from one other interface. Classes can implement some or all of the methods of an interface through inheritance from a base class. We also looked at an example of how the capabilities of an enumerated type in C or C++ can be provided in Java. Basically, one sets up a class with a private constructor that initializes a set of object variables of the class to have data fields with values you want to be in the enumeration. Then you place those values into a public array of class object variables.