Section E.18. Defining and Implementing an Interface

   

E.18 Defining and Implementing an Interface

An interface is a set of requirements to which classes must conform if they want to use the service provided by the interface. To implement an interface, first declare that your class will implement the given interface; second, define the methods in the interface.

java.util.Collection has an interface that defines, among other methods, an add() method. This ensures that any implementation of java.util.Collection will support its methods.

An interface is defined as follows :

 public interface Collection { public abstract boolean add(A o) ... } 

An interface is implemented as follows:

 public class myClass implements Collection { // code here. can write, for instance, add() since add() is a / / method of java.util.Collection ... } 

   
Top


Java for ColdFusion Developers
Java for ColdFusion Developers
ISBN: 0130461806
EAN: 2147483647
Year: 2005
Pages: 206
Authors: Eben Hewitt

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net