Win a copy of Zero to AI - A non-technical, hype-free guide to prospering in the AI era this week in the Artificial Intelligence and Machine Learning forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

small doubt

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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: 23886
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
okk got it

regards;
krishna
 
reply
    Bookmark Topic Watch Topic
  • New Topic