Difference between revisions of "Instance variable"

From Wiki @ Karl Jones dot com
Jump to: navigation, search
(Created page with "In object-oriented programming with classes, an '''instance variable''' is a variable defined in a class (i.e. a member variable), for...")
 
 
Line 3: Line 3:
 
An instance variable is similar to, but not to be confuse with, a [[class variable]].
 
An instance variable is similar to, but not to be confuse with, a [[class variable]].
  
An instance variable is not a class variable although there are similarities. It is a type of class attribute (or class property, field, or data member). The same dichotomy between instance and class members applies to methods ("member functions") as well; a class may have both instance methods and class methods.
+
An instance variable is not a class variable although there are similarities. It is a type of [[class attribute]] (or class property, field, or data member). The same dichotomy between instance and class members applies to methods ("member functions") as well; a class may have both instance methods and class methods.
  
 
Each class variable and instance variable you invoke with the object lives in memory for the life of that object.
 
Each class variable and instance variable you invoke with the object lives in memory for the life of that object.

Latest revision as of 09:06, 4 September 2016

In object-oriented programming with classes, an instance variable is a variable defined in a class (i.e. a member variable), for which each instantiated object of the class has a separate copy, or instance.

An instance variable is similar to, but not to be confuse with, a class variable.

An instance variable is not a class variable although there are similarities. It is a type of class attribute (or class property, field, or data member). The same dichotomy between instance and class members applies to methods ("member functions") as well; a class may have both instance methods and class methods.

Each class variable and instance variable you invoke with the object lives in memory for the life of that object.

Variables are properties an object knows about itself. All instances of an object have their own copies of instance variables, even if the value is the same from one object to another. One object instance can change values of its instance variables without affecting all other instances. Instance variables can be used by all methods of a class unless the method is declared as static.

See also

External links