• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

reference variable

 
saravanan ragunathan
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

i heard that when we create an array ,the reference(address) of the array will be stored in ref variable
when i executing the above statement it is executing successfully .but i gave 0 to size of array .then what will be the address assigned to variable.
 
Henry Wong
author
Marshal
Pie
Posts: 20882
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
saravanan ragunathan wrote:
when i executing the above statement it is executing successfully .but i gave 0 to size of array .then what will be the address assigned to variable.


Unlike some other languages, with Java, an array is an object -- so even if an array has no elements, it takes up some space (albeit a small amount).

Henry
 
Vinoth Kumar Kannan
Ranch Hand
Posts: 276
Chrome Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Primitive Arrays are actually objects in Java. The array object has instance variables like length(i've come across none other though..) which needs to be stored in the object space. In your case, the object will have length=0 stored in it. Of course that takes up some space,right?
 
saravanan ragunathan
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vinoth Kumar Kannan wrote:Primitive Arrays are actually objects in Java. The array object has instance variables like length(i've come across none other though..) which needs to be stored in the object space. In your case, the object will have length=0 stored in it. Of course that takes up some space,right?


thanks for your explanation...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic