Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How many objects are created by the following two statements?

 
kishore srimat
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
int[] a = new int[10];
int[][] b = new int[10][10];
 
Campbell Ritchie
Sheriff
Posts: 48910
58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't know (that is not absolutely true).

But the traditions of the Ranch are that you are supposed to tell us how many objects you think there are, then we shall look and see whether you are correct.
 
Kevin Cahill
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Being the greenhorn that I am with Java, I'm going to say 2, because each array is an object.
 
kishore srimat
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
int[] a = new int[10];

one object here

int[][] b = new int[10][10];

But here i am not sure whether it creats 10 objects ? or again one object

 
Kevin Cahill
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the HFJ book, pg. 670 shows a multidimensional array as a single object. So, my guess is each line of your example is a single object. It would be best to get clarification from an expert though...anyone?
 
Prasun Howlader
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One for First statement.
11 for second statement.
 
Raghavan Muthu
Ranch Hand
Posts: 3381
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kishore, your another *duplicate* thread has got an answer with an explanation by a bartender over here.

Kindly do NOT duplicate the threads!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic