什么是实例变量? [英] What is an instance variable?
问题描述
我是初学者.我想知道什么是实例变量.
I'm a beginner. I want to know what an instance variable is.
推荐答案
在使用类的面向对象编程中,实例变量是在类中定义的变量(即成员变量),对于该类的每个对象都有单独的副本.他们活在全班的记忆中.
In object-oriented programming with classes, an instance variable is a variable defined in a class (i.e. a member variable), for which each object of the class has a separate copy. They live in memory for the life of the class.
实例变量与类变量相反,是一种特殊类型的实例成员.实例变量的一个例子是私有双倍长度"
An instance variable is the opposite of class variable, and it is a special type of instance member. An example of an instance variable is "private double length"
从技术上讲,实例变量是存储在非静态字段"中的各个状态的对象,即未使用 static 关键字声明的字段.非静态字段也称为实例变量,因为它们的值对于类的每个实例(换句话说,对于每个对象)都是唯一的;一辆自行车的当前速度与另一辆自行车的当前速度无关.
Technically speaking, instance variables are objects stored in individual states in "non-static fields", that is, fields declared without the static keyword. Non-static fields are also known as instance variables because their values are unique to each instance of a class (to each object, in other words); the currentSpeed of one bicycle is independent from the currentSpeed of another.
参考文献:
http://en.wikipedia.org/wiki/Instance_variable
这篇关于什么是实例变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!