COSI 12b Lecture Notes - Lecture 7: Codeshare Agreement, Multiple Inheritance
Document Summary
An interface is a list of methods that classes can promise to implement. Inheritance gives you an is a relationship with code sharing. An interface gives you an is a relationship without code. Syntax: public interface {public (parameters);} Implementing syntax: public class implements {} An interface can be used as a type in parameters. For example, public static void info (shape s) {} with the interface shape will take in any class that implements the interface. An array of an interface type can be created to store class"s objects that implement the interface. Multiple inheritance is not allowed (a class can only extend one class), but multiple interfaces can be implemented. Interfaces can store constants, but they must be public, static, and final. A class that implements an interface that extends another interface must implement within the class the abstract methods of the superinterface.