Static field
A static field is a named variable whose storage is associated with a class or program scope rather than separately with each object instance.
The Well-Grounded Rubyist, Fourth Edition
A class variable is a Ruby variable whose information is shared per class hierarchy and whose name begins with two at-signs.
- How it is used
- Uses class variables to share state among a class, its methods, its instances, and its subclass hierarchy.
- How deep it goes
- Works through syntax, visibility, a counting implementation, inheritance behavior, and a class-instance-variable alternative; does not descend into runtime internals.
- Examples
- Tracks registered car makes and counts, then contrasts a shared subclass counter with a class-instance-variable counter.
- What you can do after
- Build it from scratch: implement shared class-hierarchy state and choose separate class-object state when subclass totals must differ.
Read how The Well-Grounded Rubyist, Fourth Edition explains static field →
The Well-Grounded Python Developer: How the pros use Python and Flask
A class variable is an attribute stored on a Python class and shared by its instances unless shadowed.
- How it is used
- Keeps a page-visit count accessible across instances created for separate web requests.
- How deep it goes
- Shows a working class-level counter and its single-server limit, without developing a multiple-server solution.
- Examples
- Uses PageVisit.COUNT and counts() to increment and display a page-visit counter.
- What you can do after
- Build it from scratch: implement a class-level page counter for requests handled by one server.
The Quick Python Book, Fourth Edition
A class variable is an attribute defined on a class and shared through that class's inheritance structure unless shadowed or otherwise restricted.
- How it is used
- Uses class variables for values accessible across instances, including a constant and a collection of created instances.
- How deep it goes
- Works through class-body definition, instance lookup, assignment shadowing, and inheritance without examining implementation internals.
- Examples
- Shows a circle-area constant, two instances with different pi lookups, inherited values shadowed at two levels, and an instance collection.
- What you can do after
- Build it from scratch with a class-body assignment, then update the class rather than an instance when the shared value must change.
Read how The Quick Python Book, Fourth Edition explains static field →
Python How-To
A class attribute is an attribute stored on a Python class and available to instances through attribute lookup when no instance-specific value overrides it.
- How it is used
- Shares values or resources across instances when per-instance storage would duplicate data.
- How deep it goes
- Defines placement, memory rationale, and practical uses, but stops short of detailed attribute-lookup internals.
- Examples
- Uses shared task users, SQLite connections, and Direction constants to demonstrate appropriate and inappropriate class-attribute designs.
- What you can do after
- Apply class attributes to reduce duplicated shared state and recognize when Enum is preferable for named constants.
100 Java Mistakes and How to Avoid Them
A static field is a Java class variable whose storage is associated with the class rather than with each object instance.
- How it is used
- Warns against confusing class-wide state with per-object state during refactoring, review, testing, and concurrent use.
- How deep it goes
- Explains sharing, sequential-test masking, mutable static-final state, concurrency consequences, and static-analysis detection.
- Examples
- Uses a shared Person name and a static final TreeWalker queue to demonstrate cross-object and cross-thread state leakage.
- What you can do after
- Diagnose/debug with code review, concurrency-focused tests, IDE highlighting, and static-analysis inspections.
Read how 100 Java Mistakes and How to Avoid Them explains static field →
Learn Rust in a Month of Lunches
A Rust program item representing a value stored at a fixed memory location for the entire program lifetime.
- How it is used
- Provides program-wide values that remain available for the entire program lifetime.
- How deep it goes
- Explains declaration syntax, fixed storage, lifetime, compile-time limits, and unsafe mutable access with a concurrency failure example.
- Examples
- Uses global month and season values, then contrasts a small successful counter with a large multithreaded static mut counter.
- What you can do after
- Apply static declarations for global values and diagnose why mutable static access requires unsafe code.
Read how Learn Rust in a Month of Lunches explains static field →
Get Programming with JavaScript Next: New features of ECMAScript 2015, 2016, and beyond
A property defined on a class or constructor itself rather than on instances created from it.
- How it is used
- Uses class-level values for settings shared across instances and for configuring sprite appearance.
- How deep it goes
- Defines storage on the constructor rather than instances or prototype, shows assignment-style desugaring, and stops short of deeper mechanics.
- Examples
- Demonstrates a DataStore domain, a bicycle wheel count, and shared sprite styling contrasted with unique comet shapes.
- What you can do after
- Apply static fields to place shared configuration and appearance values on classes, while keeping per-object variation on instances.
Related concepts
- attributekind of · An attribute is a named property, value, or piece of information associated with an entity, object, or program element.
- classpart of · A class is a programming-language construct that defines a type’s structure or behavior and provides a basis for creating or representing objects.
- Singleton patternused by · The Singleton pattern restricts a type or component to one shared instance within a defined scope and provides a way to access it.
- methodincludes · A method is a callable operation associated with an object or type and invoked through that association.
- bindingkind of · Name binding is the association of an identifier with the program entity or value it denotes.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.






