What is an instance variable?

后端 未结 2 1439
暗喜
暗喜 2021-02-08 19:08

I\'m a beginner. I want to know what an instance variable is.

2条回答
  •  隐瞒了意图╮
    2021-02-08 19:54

    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"

    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.

    References:

    http://en.wikipedia.org/wiki/Instance_variable

提交回复
热议问题