Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Special pages
Niidae Wiki
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Class variable
(section)
Page
Discussion
English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Page information
Appearance
move to sidebar
hide
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Examples== === C++ === <syntaxhighlight lang="cpp" line="1"> struct Request { static int count; int number; Requestobject() { number = count; // modifies the instance variable "this->number" ++count; // modifies the class variable "Request::count" } }; int Request::count = 0; </syntaxhighlight> In this C++ example, the class variable <code>Request::count</code> is [[increment operator|incremented]] on each call to the [[constructor (computer science)|constructor]], so that <code>Request::count</code> always holds the number of Requests that have been constructed, and each new Request object is given a <code>number</code> in sequential order. Since <code>count</code> is a class variable, there is only one object <code>Request::count</code>; in contrast, each Request object contains its own distinct <code>number</code> field. Also note that the variable <code>Request::count</code> is initialized only once. === Python === <syntaxhighlight lang="python"> class Dog: vertebrate_group = 'mammals' # class variable dog_1 = Dog print(dog_1.vertebrate_group) # accessing the class variable </syntaxhighlight>In the above Python code, it does not provide much information as there is only class variable in the Dog class that provide the vertebrate group of dog as mammals. In instance variable, you could customize your own object (in this case, dog_1) by having one or more [[instance variable]]s in the Dog class.
Summary:
Please note that all contributions to Niidae Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Encyclopedia:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Search
Search
Editing
Class variable
(section)
Add topic