We illustrate essential elements of Java object-oriented programming on the following example.
|
The following three classes are declared:
-
Point -- a pair of floating point coordinates in a unit square
-
Rectangle -- an ordered pair of Points
-
Canvas -- a Rectangle with additional color information
|
and they are all made Movable (i.e. they all implement Movable interface).
|
Declaration of Interface Movable:
-
public interface Movable
-
{
-
static float x = 0.0, y = 0.0;
-
public void move(float dx, float dy);
-
public void move();
-
} // end interface Movable
|