There are three kinds of variable scopes.
There can only be one copy of a static variable with a given name for a given class. It is created when the class is first referenced in your code.
There can be one copy of an instance varable with a given name for each instance of a class. It is created when the instance is created, usually with the new operator. It exists until the class instance is garbage collected.
There can be one copy of a local variable with a given name in a given method of a class. It is created when the method is called and goes away as soon as that method returns to the caller or otherwise terminates.
There are two kinds of variable types.
A reference variable usually refers to an object. It is used to access the variables and methods of the object.
A primitive variable just contains a value, either a number or a boolean value (true or false). The type of the primitive variable, int, float, etc., determines the possible values it can have.
Being an "instance variable" (i.e. being a member variable belonging to a particular object instance) and being a "reference variable" (i.e. "pointing to" some object - rather than being the object itself) are two separate things (or, as Mike put it, two things which are "orthogonal" to each other).
Looking at it another way, an "instance variable" (like "myObj.x") could, at the same time, also be a "reference variable" (as in "this.x = new someClass ()").
Did that help? Or just confuse things further for you?
[ October 03, 2004: Message edited by: Paul Santa Maria ]
Originally posted by Mike Gershman:
The terms instance and reference are orthogonal. Thanks for giving me an excuse to use that word.
Relating to or composed of right angles.
source: The American Heritage� Dictionary of the English Language, Fourth Edition Copyright � 2000 by Houghton Mifflin Company. Published by
Houghton Mifflin Company.
[ October 05, 2004: Message edited by: Layne Lund ]
Originally posted by Layne Lund:
[qb]In this context, orthogonal means that they are two separate things, as Paul tried to explain. Specifically, a variable can be BOTH an instance variable and a reference variable at the same time. They are not mutually exclusive terms.
I know what Paul was trying to explain. I just thought it funny that the title of the thread was ' ... I need a simple explanantion ....' and the word orthogonal came up. Especially as in the context that it was used is not the word's most apparent meaning.
Here is the word explained from another highly regarded source "The Compact Oxford English Dictionary"
� adjective of or involving right angles; at right angles.
In answer to the orginal question, read this section of The Java Language Specification.
[ October 06, 2004: Message edited by: Nigel Browne ]