1. Home >
  2. Apps >
  3. Groups >

Java: Is "reference variable of a class" same as "an object of that class"?

Question asked by pratap singh, upendra in #Java on Feb 17, 2016
pratap singh, upendra
pratap singh, upendra · Feb 17, 2016
Rank C2 - EXPERT
In context to Java programming,

Is "reference variable of a class" same as "an object of that class"?

Also for a code like

class Sample
int a, b;
public static void main(String arg[])
int c;
// other statements

Among the variables a,b, c which are the class variables.

Is there a difference between variable a/b and variable c as far as their scope is concerned? Posted in: #Java
Anoop Kumar
Anoop Kumar · Feb 19, 2016
Rank A2 - PRO
I assume you like to know the difference between, Instance variable and local variable.

There is certainly scope difference between variable "a" and "c".
"a/b" are class/instance variables .
"c" is a local variable defined inside the method.
scope of "a/b" is associated to instance of class, object, just like method, in your program main() method.
Better go through full tutorial of varial type and do some practice.
Java - Variable Types

You question is confusing, what exactly you are looking far?
Mohana Chandra
Mohana Chandra · Jan 13, 2020
Rank C1 - EXPERT

Reference variable is not same as Object.Both are different.

Object loads the non-static members (methods/variables) and the reference variable points to that object.Reference Variables are used for programmers convenience.

And in the above program,

a and b are called class variables.Also can be called as Non-static variables.

 c is called static variable and is a local variable to main method.

You must log-in or sign-up to reply to this post.

Click to Log-In or Sign-Up