Instance variable
An instance variable is data associated with a particular object instance, rather than data shared at the class or type level.
The Well-Grounded Rubyist, Fourth Edition
An instance variable is a Ruby variable identified by a single-at-sign prefix and associated with an individual object.
- How it is used
- Stores per-object state so methods can retrieve or change values after initialization.
- How deep it goes
- Explains assignment, persistence across calls, ownership through `self`, and inspection with `instance_variables`.
- Examples
- Uses tickets with distinct venues and dates, a person's persistent name, and runtime inspection of accessor-backed variables.
- What you can do after
- Build it from scratch: initialize per-object state, expose or change it through methods, and identify its owner using `self`.
Read how The Well-Grounded Rubyist, Fourth Edition explains instance variable →
100 C++ Mistakes and How to Avoid Them
- How it is used
- Uses instance variables to explain safe object construction and maintenance of valid object state.
- How deep it goes
- Explains defaults, declaration-order initialization, undefined behavior, and validation through problematic and corrected C++ examples.
- Examples
- Contrasts uninitialized and constructor-initialized person records, and demonstrates complex-number defaults and dependent name initialization.
- What you can do after
- Diagnoses uninitialized members and initialization-order errors, and applies constructor initialization and validation to maintain valid object state.
Read how 100 C++ Mistakes and How to Avoid Them explains instance variable →
Software Design for Python Programmers
An instance variable is state associated with an individual object instance.
- How it is used
- Models per-object state, class-owned relationships, and runtime state transitions in object-oriented application design.
- How deep it goes
- Explains state, visibility, dependencies, multiplicity, and defensive copying, but stops short of general language-level attribute mechanics.
- Examples
- Uses catalogue objects, Employee birthdates, and an automatic ticket machine to demonstrate storage, protection, and state changes.
- What you can do after
- Evaluate/understand how object state, ownership, visibility, and mutation paths affect class design.
Read how Software Design for Python Programmers explains instance variable →
100 Java Mistakes and How to Avoid Them
- How it is used
- Prevents object-specific data from becoming accidentally shared through a static field.
- How deep it goes
- Explains per-object versus per-class storage, failure under concurrency, mutable static state, and applicable inspections.
- Examples
- Uses a Person name field and a concurrent TreeWalker queue to expose shared-state leakage.
- What you can do after
- Diagnose accidental static state by comparing field ownership with object usage and applying IDE or SonarLint inspections.
Read how 100 Java Mistakes and How to Avoid Them explains instance variable →
Software Engineering for Data Scientists
An instance variable is an attribute attached to an individual object whose value may differ between instances of the same class.
- How it is used
- Uses instance variables to inspect model settings and organize data-processing state inside reusable Python objects.
- How deep it goes
- Explains definitions, constructor assignment, self, and dot-notation access, but stops short of deeper object-model internals.
- Examples
- Demonstrates random forest parameters and customer-churn data held in DataSet and CustomerData objects.
- What you can do after
- Operate/configure Python objects by defining, storing, and retrieving object-specific values through constructors and dot notation.
Read how Software Engineering for Data Scientists explains instance variable →
Secrets of the JavaScript Ninja, Second Edition
A property that belongs directly to a particular object instance rather than being inherited from its prototype.
- How it is used
- Contrasts properties stored on an object instance with properties supplied through its prototype.
- How deep it goes
- Explains constructor assignment, property precedence, and per-instance copies, then flags repeated methods as a concern for many objects.
- Examples
- Uses Ninja instances with `swung` and competing `swingSword` methods to demonstrate property ownership and precedence.
- What you can do after
- Understand which same-named property is found and why constructor-created methods are duplicated across instances.
Read how Secrets of the JavaScript Ninja, Second Edition explains instance variable →
Also covered in
- Python How-To
- Data-Oriented Programming in JavaIn early access (MEAP)
- Essential TypeScript 5, Third Edition
What to know first
- classA class is a programming-language construct that defines a type’s structure and behavior and provides a basis for creating or representing objects.
- attributeAn attribute is a named property or piece of information associated with an entity, object, or structured data item.
- exceptionAn exception is a runtime signal or value representing an abnormal condition that interrupts ordinary program flow and can be handled or propagated.
- inputAn input is information, a value, or an action supplied to a system, program, or computation for processing or to influence its behavior.
Related concepts
- accessor methodused by · An accessor method or function is a callable that reads, computes, or assigns a value associated with a property, field, or data element.
- const referenceconfigured by · A const reference is a C++ reference through which the referred-to object cannot be modified.
- stateimplements · State is information describing the condition or configuration of a system or computation at a particular time that may influence its behavior or subsequent transitions.
- objectpart of · An object is a distinct entity represented or manipulated within a computational system, typically as a value, data structure, resource, or instance of a type.
- protected memberproduced by · A protected member is a class attribute or method accessible within its defining class and, subject to language rules, within subclasses or other related contexts.
Questions about instance variable
What is instance variable?
An instance variable is data associated with a particular object instance, rather than data shared at the class or type level.
Which Manning books explain instance variable?
The Well-Grounded Rubyist, Fourth Edition, 100 C++ Mistakes and How to Avoid Them, Software Design for Python Programmers, 100 Java Mistakes and How to Avoid Them, Software Engineering for Data Scientists and Secrets of the JavaScript Ninja, Second Edition.
What should I know before learning instance variable?
Manning books that teach instance variable usually introduce class, attribute, exception and input first.
What is the difference between instance variable and prototype property?
An instance variable is data associated with a particular object instance, rather than data shared at the class or type level. A prototype property is a constructor function’s property that refers to the object used as the prototype of instances created by that function.
What is instance variable part of?
Instance variable is part of object. An object is a distinct entity represented or manipulated within a computational system, typically as a value, data structure, resource, or instance of a type.
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.





