Java methods can be overloaded (i.e. allow for multi-valued declaration with various argument patterns -- see e.g. move() method) in a similar way as class constructors.
|
Canvas inherits move() method, and overrides inverse() method (by adding color inversion, i.e. "inverse video").
|
paint() method operates on Graphics object from Sun's Java class library which is included via the import statement.
|
We used the interface construct to separate 2D translational degrees of freedoms (which are handled as Movable methods) from the internal coordinates (which are handled by individual classes).
|
Note that interfaces can only contain static (global) variables (here, x=0.0, y=0.0 which is the default origin for Point() constructor).
-
This allows one to avoid the usual ambiguities with multiply inherited instance variables in case of closed loops in the inheritance graph.
|