| 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: 3041
|
|
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: 14672
|
|
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.
|
 |
 |
|
|
subject: Clarification about creating arrays.
|
|
|