• 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
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

How many objects are created by the following two statements?

 
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];
 
Marshal
Posts: 65104
247
  • 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.
 
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?
 
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One for First statement.
11 for second statement.
 
Ranch Hand
Posts: 3389
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!
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!