• Post Reply Bookmark Topic Watch Topic
  • New Topic

Instance variable and Reference variable  RSS feed

 
nirjari patel
Ranch Hand
Posts: 386
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is instance variable and reference variable same or diferent ? Is it different names for same thing or different things altogrther ? Is there any other name they are known as (may be "object variable") ?

If they are different, then whats the difference between them ?

Thanks
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 15862
81
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
nirjari patel wrote:Is instance variable and reference variable same or diferent ? Is it different names for same thing or different things altogrther ? Is there any other name they are known as (may be "object variable") ?

Those are two different concepts. An instance variable is a non-static member variable of a class. All variables of non-primitive types are reference variables in Java. A variable can be an instance variable and a reference variable at the same time, ofcourse.

Besides instance variables, you have class variables (static member variables of a class) and local variables (locally declared in a method or other block of code).

Besides reference variables, you have variables of primitive types (byte, short, int, long, float, double, boolean, char).
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!