Dear Henry, I am confused the second statement int[][]a = new int[10][]; You said here 11 object created. But i thought here 1 object created.This array hold 10 array reference variable.
"Control time instead of letting time control you."
ahmed yehia
Ranch Hand
Joined: Apr 22, 2006
Posts: 424
posted
There are actually 11 objects created, because the array is instantiated using 'new' all ref. variables are assigned to new array objects.
Jim Yingst
wanderer
Sheriff
Joined: Jan 30, 2000
Posts: 18602
posted
For the second statement, there is one int[][] array, and ten int[] arrays. The first array holds references to the other ten, which represent individual rows. The statement is equivalent to the following code:
"I'm not back." - Bill Harding, Twister
Prasun Howlader
Ranch Hand
Joined: Oct 21, 2007
Posts: 89
posted
1. int[][] a = new int[10][]; 2. int[][] b = new int[10][3];
This two statement each generate 11 object is it true? [ January 26, 2008: Message edited by: Prasun Howlader ]
Jim Yingst
wanderer
Sheriff
Joined: Jan 30, 2000
Posts: 18602
posted
No.
And perhaps I should correct the second comment in my previous post:
Prasun Howlader
Ranch Hand
Joined: Oct 21, 2007
Posts: 89
posted
I am sorry because henry told for this statement int[][]a = new int[10][10] and he/she is right.
Henry Wong
author
Sheriff
Joined: Sep 28, 2004
Posts: 11293
posted
Originally posted by Prasun Howlader: I am sorry because henry told for this statement int[][]a = new int[10][10] and he/she is right.
I don't understand your confusion here.
I mentioned:
int[] a = new int[10]; // creates one object
int[][] b = new int[10][10]; // creates eleven objects
Jim mentioned:
int[][]a = new int[10][]; // creates one object only
int[][]b = new int[10][3]; // creates eleven objects
There is no contradiction here. Your response implies that Jim stated something that conflicts with what I stated. Could you elaborate on why you think which of the four statements are in conflict?
Henry
Prasun Howlader
Ranch Hand
Joined: Oct 21, 2007
Posts: 89
posted
Both jim and henry were right. Actually i am confusing this statement
int[][]a = new int[10][];
Now i am clear.
Sid Robin
Ranch Hand
Joined: Nov 24, 2007
Posts: 53
posted
why is that the statement Delta []a[] = new Delta[10][10] for Delta Java Program creates only one object "a" which is array object ? contrary to what every one has explained ?
Jim Yingst
wanderer
Sheriff
Joined: Jan 30, 2000
Posts: 18602
posted
It's not possible to explain that, because it's not true.
subject: How many objects are created by the following two statements?
JProfiler
Get rid of your performance problems and memory leaks!