Fields
Fields comprise the primary “data” portion of a class. They are synonymous with attributes, describing the features of a class. Their types could be primary types, user defined structures, or other classes. Although fields represent information about a class, can also be thought of as self-contained objects, each with their own behavior.
Field Initialization
Fields can be initialized during declaration or afterward, depending on style and/or the nature of requirements. There are pros and cons each way.
For example, a conservative approach may be to ensure that all fields have default values, which would lead to initialization of fields at declaration or soon thereafter. This is safe and perhaps it also helps plan design more thoroughly ...
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