Static Members and Class Constants
Share data and helpers at class level.
Shared, Not Per-Instance
Most members belong to each object, but some belong to the class itself. Those are called static members, shared by everyone.
A Static Field
Mark a field static and it exists once for the whole class, not once per instance. All objects see the same value.
class Dog {
static int count = 0;
}All lessons in this course
- Defining a Class With Fields
- Instance Methods and this
- Getters and Setters
- Static Members and Class Constants