Interfaces in Java
Today's notes - Interfaces
Terminology
- interface
- An interface specifies behavior for a class. - Gaddis definition
It is also the keyword that defines the interface
- implements
- the java keyword that indicates that a class is implementing a
specified interface
Notes
- interfaces provide method headers. May also provide constants. May not
provide attributes (because these are not inherited).
- a class implementing an interface must implement each of the interfaces
methods...this is the contract.
- interfaces provide a "multiple inheritance" mechanism. It is not
inheritance, but classes that implement the same interface can be treated
as if they share the "is-a" relationship.
- interfaces may be exteded. The method headers (contractual
requirements) are inherited. Implementing classes must implement all
methods in the child and all ancestors.
Syntax
declaration
visibility interface
name
using
visibility class
name
implements
interfaceName
Examples
Relatable.java
FinalExam3.java
InterfaceDemo.java
GradedActivity.java
CS 239 - Fall 2006