• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Will memory be allocated

 
faisal usmani
Ranch Hand
Posts: 139
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello ranchers ,

If we write

int a[] = new int[10];

we know 40 bytes of memory will be allocated .

but what if i write

int a[] = new int[0] ;

will memory be allocated , if yes why ?


Thanks in advance
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24204
34
Chrome Eclipse IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your basic assumption is invalid. You don't know that 40 bytes will be allocated -- you know that more than 40 bytes will be allocated, but you don't know how much more. A zero-element array does indded have a finite size, but the size is dependent on the JVM implementation, not something you can find out from the Java language itself.
 
faisal usmani
Ranch Hand
Posts: 139
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks sir ,

got the point
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic