If a class C implements an interface I it signs a contract saying: you can treat
me as an I instead of a C. It adds another 'face' to the class. Implmenting a
interface is easy; e.g.
-
// the interface:
-
public interface I
-
public int aMethod();
-
public int anotherMethod();
-
}
-
// the implementing class:
-
public class C implements I {
-
// complete implementation of I
-
public int aMethod() { return 42; }
-
public int anotherMethod() { return 54; }
-
}
-
If a class says it implements an interface as in "implements I" but it doesn't
implement all of the methods of the interface, the class must be abstract so
that a derived class can complete the implementation of the interface:
-
public abstract class C implements I {
-
public int aMethod() { return 42; } // partial implementation of I
-
// no implementation of anotherMethod()
-
}
-
public class Derived extends C {
-
public int anotherMethod() { return 54; } // completes implementation of I
-
}
-
This all is completely explained in your textbook; read it.
kind regards,
Jos