Laundry once more |
As a final example using arrays and inheritance, take a look at array-based laundry. Notice how the class LaundryImpl has an incomplete constructor that doesn't bother to initialize the array parts. As a result, we should never create an object from this class. (We usually mark such classes as "abstract" so that the Java compiler will prevent us from creating a new object from it.)
Then what is the point of such a class? It is there solely for other classes to inherit from it. In our case, we can write subclasses like Pants and Tshirt that provide new constructors, but inherit all of the other methods (sometimes we'll revise inherited methods or add new ones, but that is not needed here).
Laundry once more |