Quick Instantiation Question
This came to my attention on page 274:
Animal[] animalArray = new Animal[2];
Cow myCow1 = new Cow("Deirdre");
animalArray[0] = myCow1;
animalArray[1] = new Chicken("Ken");
My question is why do you need to prefix myCow1 with Cow, but you do not need to prefix animalArray[1] with Chicken.
In this line: Cow myCow1 = new Cow("Deirdre");
The first Cow is the type (like int, string, etc.), and the second Cow() is the constructor, correct?
So why does the Chicken not need the type declaration?
|