Written by the Fiveable Content Team โข Last updated September 2025
Verified for the 2026 exam
Verified for the 2026 examโขWritten by the Fiveable Content Team โข Last updated September 2025
Definition
Static variables are variables that belong to the class itself, rather than an instance of the class. They are shared by all instances of the class and can be accessed without creating an object of the class.
These are variables that belong to individual instances (objects) of a class and have different values for each instance.
Class Variables: Similar to static variables, these are also shared by all instances of a class. However, they can be inherited by subclasses.
Local Variables: These variables are declared within methods or blocks and exist only within their scope. They cannot be accessed outside their respective methods or blocks.