What Is an Instance Variable?

In class declarations, attributes are represented by variables. Such variables are called instance variables and are declared inside the class declaration but outside the other member methods of the class. Each object of the class maintains its own copy of the instance variables.

Instance variable

Right!
In class declarations, attributes are represented by variables. Such variables are called instance variables and are declared inside the class declaration but outside the other member methods of the class. Each object of the class maintains its own copy of the instance variables.
Chinese name
Instance variable
Foreign name
The instance variables
Meaning
Defined in a class but outside any method
In class declarations, attributes are represented by variables. Such variables are called instance variables and are declared inside the class declaration but outside the other member methods of the class. Each object of the class maintains its own copy of the instance variables.
It is a reference to i through a class instance, so it belongs to a given object. The instance variable has the letter @, for example:
@hello = hello
Instance variables can be obtained from outside the class to which they belong, but only through accessor methods. [1]

IN OTHER LANGUAGES

Was this article helpful? Thanks for the feedback Thanks for the feedback

How can we help? How can we help?