What is default size of Reference Variable ?

#2
size of refference variable is 4 byte becoz reffernce variable always of int type by default.

A refference variable is a local variable so it must be initalized by some value or obect.
value--->null
that mean's it i not reffering to any object....
 
Last edited:
#3
size of refference variable is 4 byte becoz reffernce variable always of int type by default.
A refference variable is a local variable so it must be initalized by some value or obect. value--->null that mean's it i not reffering to any object....
Hi Gauravtaneja,

In my opinion Reference variable default size is 8 bytes. Ok we consider your answer that is "referenced variable default size is 4 bytes and its type is int" as correct, then it is not possible to assign a null value to the int variable

Am I right or not? I am also not sure about it, so plz once check with your answer and justify your answer.

Thank U
 
#5
Hi,
I think Above answers are wrong i agree with mr. balu. The default size of ref of the varibale is depend on the type of type of variable, becoz we can create ref variable to int, float, String, Class, Interface, etc.
 
#6
I dont think so that size of reference variable is depand on the type, if yes then what about if the return type is a "class" type, how many it takes now???
 
#10
Size of a reference variable can never depend on the type of value it points to. In any case it always stores an address.
Now the bytes reqd to store that address might depend upon the JVM (um not sure)
 
Last edited:
#12
-Default size of Reference Variable is 8 bytes.
-Default value is NULL
hi I am gaurav I have consulted with books and i found that refernce variables are local variable just like as ponter in c/c++ and as we know that local variable lies on stack so they must be initalized with some value otherwise we will get compile time error so we can initalize referce variable only null or Object. Am I right
 
#13
woo woo wooo hold on guys !! wat are u guys thinking...dont think complex...its simple.....size of reference variable is INDEPENDENT of the data type....
and its size is 4bytes as some one sed above !!
and its value is null default...
 
#16
hi friends i am reading all answer regarding question.
i want to give an example

class a{
}

above is class declaration and then we declare refrence variable
like
a o; <---- This is reference variable
a o=new a();<-----This is creating an object so here o is the object (a reference variable which hold address of an object)

So,if we only declare refrence variable then its value is null it means no size.
and if we declare as a second type then the value is a address which is a hexa decimal value
 
#17
as we knw while creating the object we use "new " operator it returns the addr of the memory location and this adrr is going into store inside the reference variable thats y it should depend on the jvm not on the type of the variable..........
 
#18
ooF.. what is the correct answer of these
am totally confusing , can anybody give me proof(Book) for size of reference varaible please

thanks in advance
 
#19
Hi,
Sorry for late reply.
Actually in my opinion refference variable(a special variable that reffers object) is much simillar with pointers in C,there are lot's of diffrences too.But in case of size both of them have simillarity both of them have int type so in case of C-language pointer type is 2 byte and in case of java we have 4byte size.I agree it, default value is null. and it's a local variable that means it lies on stack it must be initalized by null or some object refference.
 
Top