Constructors
The primary purpose of a constructor is to initialize an object. Initialization consists of setting the initial state of class fields. Because of definite assignment rules, it's often desirable to initialize your fields in constructors. This section shows how to gain full control over field initialization.
There are two categories of constructors: static and instance. Each category defines what fields can be initialized and the sequence of initialization. If need be, both types of constructors can be used in a single class. Just be careful to design your class properly. Using both types of constructors in the same class could be an indication of a class possibly supporting multiple roles—which may complicate a design.
Instance Constructors ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access