previous | start | next

Interfaces

Recall that an Interface looks like a class, but there are no data
members, and no implementations of methods  - just the method
prototypes (return type, name, list of argument types).

An Interface still defines a "type", but we cannot directly
create instances of an interface.

Example:

interface Comparable<T>
{
   public int compareTo(T other);
}

What does it mean for a class toimplement an
interface?

class X implements Comparable<X>
{


}

It means 

a. class X must include the  method int compareTo(X other) and with
an implementation.

b. It means that for any variable of type X can be compared to any
      other variable of type X.



previous | start | next