| Author |
How many objects?
|
Shiva Mohan
Ranch Hand
Joined: Jan 05, 2006
Posts: 465
|
|
int[][] i=new int[1][2];//total 4 objects are created int[][] i=new int[2][2];//total 7 objects are created Am i correct? is there anyway to find out how many objects are created in coding way?Please help.
|
 |
Anton Uwe
Ranch Hand
Joined: Jan 10, 2007
Posts: 122
|
|
Mhhh, in my opinion the following is correct: A) int[][] i=new int[1][2]; // will create 2 Objects B) int[][] i=new int[2][2]; // will create 3 Objects In A) the first object is referenced by "i", the second by "i[0]". In B) the first is ref. by "i", second and third by "i[0]" and "i[1]". Edit. Added comment. [ February 25, 2007: Message edited by: Anton Uwe ]
|
 |
pete stein
Bartender
Joined: Feb 23, 2007
Posts: 1561
|
|
Good golly, and I'm' here to suggest a totally different answer??? When I run this code I see 3 objects for the first case and 5 for the second: It also depends on what you mean by "objects". I'm refering to places in memory that hold a value. /Pete [ February 25, 2007: Message edited by: pete stn ]
|
 |
Keith Lynn
Ranch Hand
Joined: Feb 07, 2005
Posts: 2341
|
|
|
I agree with Anton. The elements of an int[] aren't objects.
|
 |
pete stein
Bartender
Joined: Feb 23, 2007
Posts: 1561
|
|
Originally posted by Keith Lynn: I agree with Anton. The elements of an int[] aren't objects.
Oops I stand corrected. Keith Lynn is correct. My lame excuse is that I come to Java from the c# world, and in c# everything, even a primitive type, is a subclass of Object. [ February 25, 2007: Message edited by: pete stn ]
|
 |
 |
|
|
subject: How many objects?
|
|
|