• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

small doubt

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
when we creat a 1-D array how many objects are created on heap one or two..
eg : int [] dots={6,7,8}
 
Ranch Hand
Posts: 173
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For the given example since it is a 1-D primitive array it will create one object on heap.

Can you elaborate your doubt so that we can explain better ?
 
krishnaa yadav
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
the followin code can be written as
int[] dots;
dots = new int [3]

so if we draw a heap stack diagram it would be

2000 and 3000 assumed memory location

From line 1
------------
HEAP
2000:int[] arrobjct

STACK
2000:dots


From line 2
-------------
HEAP
2000:int[] arrobjct----->3000
3000:int[3]: 6 7 8(value would be assigned)

STACK
2000:dots

finally there are 2 objcts created one at 2000 location and other at 3000 location ....
if i am wrong please correct...

 
author
Posts: 23958
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

krishnaa yadav wrote:the followin code can be written as
int[] dots;
dots = new int [3]



The first line only declares an array reference -- no objects are allocated (instantiated) at this time. Granted, if the variable is a local variable, then some space is allocated for it, but that doesn't make it an object.

With the second line, an object is instantiated. And the variable, declared earlier is referenced to it.

Henry
 
krishnaa yadav
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
okk got it

regards;
krishna
 
No holds barred. And no bars holed. Except this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic