• Post Reply Bookmark Topic Watch Topic
  • New Topic

Clarification about creating arrays.  RSS feed

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Hal,

Welcome to Java Ranch..

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

Regards,
Antany


 
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
 
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
 
Hal Videira
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for clearing that up, and also for the greetings.
 
Get out of my mind! Look! A tiny ad!
The WEB SERVICES and JAX-RS Course
https://coderanch.com/t/690789/WEB-SERVICES-JAX-RS
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!