Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

referance variables  RSS feed

 
sree visu
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
could anyone please explain me what is a reference variable,reference object?please clarify with an example simple code
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, try the Campfire Story about Cup Sizes. It's a great overview of how variables work.
 
sree visu
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am a bit vague about the concept.Actually please do verify my answer if i am correct.

for example consider the following code



Is the variables x,y are the reference variables as mentioned in (1).if so they are simply the instance variables.Are they referance variables?

In code segment (2)

simply here we are passing the object.Is it so?or is it an object reference?
please help regarding this please................
 
Sviatoslav Vestimskiy
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. No, x and y from first segment are not reference variables, they are primitives.
2. No, you don't pass an object here, you pass the reference to it. In fact you never pass or call objects in java.
[ July 10, 2007: Message edited by: Sviatoslav Vestimskiy ]
 
Campbell Ritchie
Marshal
Posts: 55717
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sviatoslav Vestimskiy is quite right that x and y are primitives.

Simply: a primitive type is one where the memory location points to the value of the variable. That means, boolean, byte, char, double, float, int, long and short.

A reference type means the memory location has details of the reference where the values are to be found. That means, everything else. "Reference type" means more-or-less the same as "any type which is an object."
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!