Class Fields
The fields of a class constitute its data, what the compiler will allocate in memory when an object of this class is instantiated. The fields are fundamental to the class: Defining the correct fields is crucial. This is normally done as part of the design stage of the software development life cycle (SDLC).
Class fields can have access modifiers similar to the ones you encountered for the structure fields:
Public means that the field is accessible by anyone in this project and in other projects that use the class. Anyone can get the value of the field and set it back (if it is not a constant field).
Private means that the field is not visible to anyone but the object itself. You will see in the next chapter why this is useful.
Protected ...
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