Discussion
Ask a question about 'Member variable'
Start a new discussion about 'Member variable'
Answer questions from other users
|
In
object-oriented programmingObject-oriented programming is a programming paradigm using "objects" – data structures consisting of data fields and methods together with their interactions – to design applications and computer programs. Programming techniques may include features such as data abstraction,...
, a
member variable (sometimes called a
member fieldIn computer science, data that has several parts can be divided into fields. Relational databases arrange data as sets of database records, also called rows. Each record consists of several fields; the fields of all records form the columns....
) is a
variableIn computer programming, a variable is a symbolic name given to some known or unknown quantity or information, for the purpose of allowing the name to be used independently of the information it represents...
that is associated with a specific
classIn object-oriented programming, a class is a construct that is used as a blueprint to create instances of itself – referred to as class instances, class objects, instance objects or simply objects. A class defines constituent members which enable these class instances to have state and behavior...
, and accessible for all its
methodsIn object-oriented programming, a method is a subroutine associated with a class. Methods define the behavior to be exhibited by instances of the associated class at program run time...
. If there is only one copy of the variable shared with all instances of the class, it is called a
class variableIn object-oriented programming with classes, a class variable is a variable defined in a class of which a single copy exists, regardless of how many instances of the class exist.A class variable is the opposite of an instance variable...
or static member variable. If each instance of the class has its own copy of the variable, the variable is called an
instance variableIn object-oriented programming with classes, an instance variable is a variable defined in a class , for which each object of the class has a separate copy. They live in memory for the life of the object....
.