• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

hello... i need simple explanation for this......

 
okey yd
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everyone, i just want to hear from you your simple explanation regarding the difference of instance variables and object reference variables or reference variables. what it really means to say that this is an instance variables. and what it means to say that this is object reference variable. thank you.
 
Mike Gershman
Ranch Hand
Posts: 1272
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The terms instance and reference are orthogonal. Thanks for giving me an excuse to use that word.


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.
 
Paul Santa Maria
Ranch Hand
Posts: 236
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did Mike's explanation answer your question?

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 ]
 
Nigel Browne
Ranch Hand
Posts: 703
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

HTH

Layne
[ October 05, 2004: Message edited by: Layne Lund ]
 
Nigel Browne
Ranch Hand
Posts: 703
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

HTH

Layne

[qb]


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"

orthogonal
/orthoggn�l/

� 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 ]
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Nigel Browne:


I know what Paul was trying to explain....
[ October 06, 2004: Message edited by: Nigel Browne ]


My apologies. I thought you were the OP. I guess I should double check before I go running my mouth, so to speak ;-)
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic