9

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

2 Answers 2

7

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

Sign up to request clarification or add additional context in comments.

1 Comment

Objective-C does not have static fields. In fact the idea of static fields/methods is really an implementation detail in C++ like languages. It's the C++/Java way of implementing class methods and fields.
3

You probably mean "instance" variable. It is a variable that is associated with instances of a class. For each instance of a class you create, that variable is also created.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.