File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes How many objects are created by the following two statements? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How many objects are created by the following two statements? " Watch "How many objects are created by the following two statements? " New topic
Author

How many objects are created by the following two statements?

kishore srimat
Greenhorn

Joined: Dec 18, 2007
Posts: 5
int[] a = new int[10];
int[][] b = new int[10][10];
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40052
    
  28
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

Joined: Jan 08, 2008
Posts: 9
Being the greenhorn that I am with Java, I'm going to say 2, because each array is an object.


Persistence and determination alone are omnipotent.<br />---Calvin Coolidge
kishore srimat
Greenhorn

Joined: Dec 18, 2007
Posts: 5
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

Joined: Jan 08, 2008
Posts: 9
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

Joined: Oct 21, 2007
Posts: 89
One for First statement.
11 for second statement.


"Control time instead of letting time control you."
Raghavan Muthu
Ranch Hand

Joined: Apr 20, 2006
Posts: 3355

Kishore, your another *duplicate* thread has got an answer with an explanation by a bartender over here.

Kindly do NOT duplicate the threads!


Everything has got its own deadline including one's EGO!
[CodeBarn] [Java Concepts-easily] [Corey's articles] [SCJP-SUN] [Servlet Examples] [Java Beginners FAQ] [Sun-Java Tutorials] [Java Coding Guidelines]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How many objects are created by the following two statements?