What is default size of Reference Variable ?

Discussion in 'Object Oriented Concepts' started by vbraojava, Sep 8, 2008.

  1. vbraojava

    vbraojava New Member

    -Default size of Reference Variable is 8 bytes.
    -Default value is NULL
  2. gauravtaneja

    gauravtaneja New Member

    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.
    that mean's it i not reffering to any object....
    Last edited: Nov 6, 2008
  3. vbraojava

    vbraojava New Member

    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
  4. bobbybalu44

    bobbybalu44 New Member

    The default size of a reference variable depends on the type of reference variable
  5. pavan_ravula

    pavan_ravula New Member

    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. ankushsoni11

    ankushsoni11 New Member

    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???
  7. anand853

    anand853 New Member

    any one can tell size of reference variable is depand on the type or not:confused:

    Anand Pasunoori
  8. ankushsoni11

    ankushsoni11 New Member

    Reference variable size is depands on the type of JVM...:)
  9. anand853

    anand853 New Member

    can i have specific ans...

    how and why

    anand pasunoori
  10. nehasood

    nehasood New Member

    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: Dec 16, 2008
  11. sandyfpatil

    sandyfpatil New Member

    default size of Reference Variable is number of bytes req'd to store address..
  12. gauravtaneja

    gauravtaneja New Member

    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. wilson.palkuri

    wilson.palkuri New Member

    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...
  14. raj123

    raj123 New Member

    hello dear friend size of reference variable by default is 8 byte.:)
  15. raj123

    raj123 New Member

    hello dear friend size of reference variable by default is 8 byte, dear friend its right that it has integer means its like address as pointer in c/ c++.:)
  16. haipankaj21

    haipankaj21 New Member

    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
    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. hmnland

    hmnland New Member

    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. hrushi5n

    hrushi5n New Member

    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. gauravtaneja

    gauravtaneja New Member

    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.
  20. venkatkirankumar

    venkatkirankumar New Member

    I dont think so.Because java doesn't have any size of operator to find size . we cant justify it is 8 bytes

Share This Page