«^»
10.1. What is an interface?

Earlier, in The role of a class, it was suggested that, when looking at a class declaration, you should distinguish between the text that describes what services are offered and the text that describes how these services are provided. The what describes the interface whereas the how describes the implementation. Java allows us to document the what by means of a construct called an interface.

So, in Java, an interface is a construct that gives a list of related methods (and/or constants). Here is an example that lists a set of methods for manipulating a date:

0758: public interface DateIF {
0759:    public int getYear();
0760:    public int getMonth();
0761:    public int getDay();
0762:    public void setYear(int pYear);
0763:    public void setMonth(int pMonth);
0764:    public void setDay(int pDay);
0765:    public boolean equals(Object pObject);
0766:    public int hashCode();
0767:    public String toString();
0768: }
With a class, we use new and a constructor (i.e., a class instance creation expression) to create an object, an instance of the class. It does not make sense to create an instance of an interface (and for this reason an interface does not have a constructor).