June 2025
Intermediate to advanced
1093 pages
33h 24m
English
The fact that static is also used for a completely different purpose takes some getting used to. You can use it to mark a data field or a method of a class to share it among all instances of the class. Or to put differently:
static for a data fieldWhile there is always one instance of a normal data field per instance, all instances share a common data field marked as static. Therefore, there is exactly one instance of this data field per class and not as many as there are instances.
static for a methodA static method lacks the this pointer. Within the method, there is no connection to a specific instance of the class. Therefore, you do not call the method via an instance with . or ->, but rather via the class ...
Read now
Unlock full access