<?xml version="1.0" encoding='utf-8'?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml">
<wml>
<card id="card1" title="Instance variable - Page 5 - Wikipedia">
<p>
<a accesskey="1" href="page.php?w=instance_variable&amp;p=4">1.Previous</a><br />
<a accesskey="3" href="page.php?w=instance_variable&amp;p=6">3.Next</a>
</p>
<p>if the value is the same from one object to another. One class instance can change values of its instance variables without affecting all other instances. A class may have both instance variables and <a href="page.php?w=Class_variable">class variables</a>.</p>

<p>Instance variables can be used by all instance methods of an object, but may not be used by class methods. An instance variable may also be changed directly, provided <a href="page.php?w=Access_modifiers">access restrictions</a> are set.</p>

<p><big>Examples</big></p>
<p><big> C++ </big></p>
<p><syntaxhighlight lang="cpp">class Request {private:    static inline int count1 = 0;    int number;public:    // constructor modifies the instance variable "this->number"    Request():        number{count1} {        ++count1; // modifies the class variable "Request::count1"    }</syntaxhighlight></p><p>
<a accesskey="1" href="page.php?w=instance_variable&amp;p=4">1.Previous</a><br />
<a accesskey="3" href="page.php?w=instance_variable&amp;p=6">3.Next</a>
</p>

<do type="prev" label="Search">
        <go href="search.wml"/>
</do>

</card>
</wml>
