Introducing Construction (Chapter 14)

SOLUTION 14.1Special rules regarding constructors include the following.
  • You must use new to invoke a constructor.

  • Constructor names must match the class name. This results in the oddity that, unlike most methods, constructor names normally begin with an uppercase letter.

  • If you do not supply a constructor for a class, Java will provide a default.

  • You can invoke other constructors with this() and super() so long as this invocation is the first statement in a constructor.

There are also several rules governing the order of field initialization and special rules for the instantiation of arrays.

SOLUTION 14.2A constructor that allows Fountain to compile is:
public Fountain(String name)
{
    super(name);
}

This constructor ...

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.