Java Reference
In-Depth Information
Figure 10.3
The Rectangle class implements the Paintable class.
Notice that the Rectangle class declares that it implements Paintable, but it
does not contain the paint() method. I did this intentionally to show you the
compile error that is generated. Continue on to the next step, and see what
happens.
Save and Compile the Rectangle Class
Save the Rectangle class in your c:\interface directory. Compile Rectangle.java
using javac. You should get a compiler error similar to the one in Figure 10.4
because Rectangle is neither declared abstract, nor implements the paint()
method in Paintable.
If you want a quick fix for your Rectangle class, simply declare it as
abstract:
public abstract Rectangle implements Paintable
It will compile now, but you will not be able to create any Rectangle
objects because it is an abstract class.
Figure 10.4
The Rectangle class does not properly implement Paintable.
Search WWH ::




Custom Search