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 Clarification about creating arrays. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Clarification about creating arrays." Watch "Clarification about creating arrays." New topic
Author

Clarification about creating arrays.

Hal Videira
Greenhorn

Joined: Aug 13, 2009
Posts: 2
Hi Guys,
I have been sent to this forum head first.



On line 2, my understanding is that a new array with space for 3 Dog reference variables is created. Then the array is assigned to the variable myDog which is of type Dog. Is this correct?

Many Thanks,

Hal

Antany Vasanth
Ranch Hand

Joined: Jan 28, 2009
Posts: 43
Hi Hal,

Welcome to Java Ranch..

If "dog1" is instance of Dog then the code is correct.

Regards,
Antany


Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4181
    
  21

Hal Videira wrote:On line 2, my understanding is that a new array with space for 3 Dog reference variables is created. Then the array is assigned to the variable myDog which is of type Dog. Is this correct?


Welcome to JavaRanch!

You are almost correct:
"a new array with space for 3 Dog reference variables is created"
Correct

"Then the array is assigned to the variable myDog"
Correct

"myDog ... is of type Dog."
Incorrect. The type of myDog is Dog Array, or Dog[]. If it were of type Dog, for instance, you would be able to do this:

Since both yourDog and myDog would be the same type. But that would fail.

myDog is of type Dog Array, which holds references of type Dog.

Steve
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

Is this correct?

Almost. Except that the array is assigned to the variable myDogs which is of type array of Dog.
But you've got the main point.


[My Blog]
All roads lead to JavaRanch
Hal Videira
Greenhorn

Joined: Aug 13, 2009
Posts: 2
Thanks for clearing that up, and also for the greetings.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Clarification about creating arrays.