Instance variable
| This article does not cite any references or sources. Please help improve this article by adding citations to reliable sources. Unsourced material may be challenged and removed. (December 2009) |
| This article may need to be rewritten entirely to comply with Wikipedia's quality standards. You can help. The discussion page may contain suggestions. (February 2010) |
In object-oriented programming with classes, an instance variable is a variable defined in a class (i.e. a member variable), for which each object of the class has a separate copy. They live in memory for the life of the object.
An instance variable contrasts with a class variable, and it is a special type of instance member. An example (C++ or Java) declaration of an instance variable is:
private double length;
Technically speaking, instance variables are objects stored in individual states in "non-static fields", that is, fields declared without the static keyword. Non-static fields are also known as instance variables because their values are unique to each instance of a class (to each object, in other words); the currentSpeed of one bicycle is independent from the currentSpeed of another. A simpler definition is that instance variables are things an object knows about itself.
A typical declaration in Objective-C would look like:
@interface CustomClassName : NSObject{
NSString *ivar;
}
| This computer programming-related article is a stub. You can help Wikipedia by expanding it. |