What Is 'Reference Variable' In Java?


20 Answers

James Harden Profile
James Harden answered
"A reference in Java Script affectively means a variable data type whose value takes the form of an address. A variable in Java Script is a terms that is used for an item of data that is named by an identifier. Each of these variables has a type which it can be classified under, such as 'int' or 'Object' and a scope. Commonly, in Java, variable have to be one of two types: 'Primitive' type or 'reference' type, and cannot be both. This statement leads to major simplifications within the syntax involved in certain expressions that are relative to C++. This provides a vast amount of flexibility for programmers using Java Script, but can lead to errors that are undetectable when compiling, and are only shown to exist when the written program is actually running.    

A reference variable in Java contains an address, or a reference to an address (similar to pointer variables in C++). Java does not, however, allow this address to be arbitrarily (randomly) edited or changed in any way. This goes for pointer variables in C++ as well. So, reference variables are similar to pointer variables in C++. They provide a method through which to access another variable or memory address that has a variable, and allow changes to the data within the afore-mentioned memory address. A reference variable provides direct access to this memory address.
Anonymous Profile
Anonymous answered
Reference variable is one which holds reference(points to) to a an instance(object) of a class..
If I say, Box b..then b is a reference variable of type Box(where Box is a class).Now it can hold reference to any instance of class Box or of classes derived from it as described below:

Box b=new Box();
new Box() creates a instance of class Box.So b is now pointing to an object of class Box or in other words holding a reference to an instance of class Box.
jeet parmar Profile
jeet parmar answered
A reference variable can hold the reference of an object, but when we call any method by using reference variable then always call only those method which type of object we create.
Class Animal{
void eat(){  sop("animal class"); }
Class Dog extends Animal{
void eat(){  sop("dog class"); }
Class Cat extends Animal{
void eat(){  sop("cat class"); }
Animal a = new Animal();
Animal b = new Dog();
Animal c = new Cat();;// animal class;// dog class;// cat class

so don't confuse it just only reference variable.
Lakshmipriya Nair Profile
Java variables refer to things that contain data which undergoes change when a particular program is executed. It is necessary to declare a variable i.e. To notify the compiler and the type of the variable before using a variable. There are different types of variables in a java program. Some of them are primitive type and reference type.    A reference type of variable is generally defined as variables where their names can evaluate to the address of the location found in the memory. The object that is referenced buy the variable is stored in this place. Thus it is known as reference variable due to its function in a Java program. A variable can either be primitive type or a reference type and cannot be both at the same time. Each has its own specific needs and requirements.
Anonymous Profile
Anonymous answered
Class Refvar{ //code }
Refvar var1;     \\ reference variable
Refvar var2 = new Refvar;   \\ variable
var1 = var2;   \\ var1 referencing to memory address of var2

[ memory of var2 ]
Anonymous Profile
Anonymous answered
The variable used to store the reference of object is reference variable
  obj a=new obj();
in this a is reference variable...
ashutosh singh Profile
ashutosh singh answered
Reference variable refers the object
Button b=new button();
here b is the object of button
b is a reference variable of tybe button
ravi kumar Profile
ravi kumar answered
Reference  variable means  refer to the class with an object.  I.e a whole class property is represented by the object itself...

Ravi Kumar
nettech india Profile
nettech india answered

A reference variable is declared to be of a specific type and that type can never be changed. Reference variables can be declared as instance variables ,static variables, method parameters, or local variables.

Anonymous Profile
Anonymous answered
A variable is something that can store data, such as numbers and words.
One of the common types of variables is called "int", which can store
Creating a variable is simple:
Int myVar;
is the data type of the variable, and "myVar" is the name of the
variable, you can choose almost any name you want for your variables.
Then you can assign a number to this variable, you can even use negative numbers:
MyVar = 5;
Notice how you do not need to type "int" again, you only need to do it once when you create the variable.
Here's how to add numbers to variables:
MyVar = myVar + 4;
myVar += 4;
When you do either of these it will add 4 to the value of myVar, which means myVar now equals 9. (5 + 4 = 9)
You can also use subtraction: -
Multiplication: *
Division: /
and Modulus: %

Another important data type is the String, a String can store words and letters, and behaves much like an int.
String myVar;
myVar = "Hello";
myVar += " there, Sir.";
Now, like we did with the int earlier, myVar equals "Hello there, Sir."
One last thing, you can add different variables together, but they must be the same data type:
MyVar += anotherVar;
Anonymous Profile
Anonymous answered
A reference variable is that which have no memory space is allocated.

For example:
A is our class then
A obj;
obj is a reference of class A.
Guru Prasad Misra Profile
A variable that does not have the value with it , but it refers to another variable for the values ....

Example--: Int I,j;
If you are using the object j in a class and accessing a file from another class then you have to take the help of the DOT(.) operator.... Here "j" is the reference variable and I is the value variable....
thanked the writer.
Anonymous commented
Heyy Mishra...i think u forgot u mntn dat reference variable does not allocate any memory space.Am i rght ?

Answer Question