Superclass Collaboration

Eventually, a constructor always collaborates with one of its superclass's constructors. If a class has no declared constructor, Java supplies a default one equivalent to a constructor with no arguments and no statements. If the first statement in a constructor is anything other than a specific invocation of another constructor, Java inserts a call to super(), the superclass's constructor with no arguments. This causes a compilation error if the superclass does not provide a constructor with no arguments.

In Figure 14.1, for example the classes capture the idea that a fountain is one type of firework. (A fountain is a ground-based firework that emits a spray of sparks.) Suppose that at an early stage of development, we ...

Get Design Patterns Java™ Workbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.