liveBook · Manning

Instance variable

An instance variable is data associated with a particular object instance, rather than data shared at the class or type level.

How 6 Manning books explain it

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

What to know first

Related concepts

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.