O'Reilly Forums: Chapter 8 Example Code - O'Reilly Forums

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Chapter 8 Example Code Is the code on page 207 complete?

#1 User is offline   wfc7 

  • New Member
  • Pip
  • Group: Members
  • Posts: 1
  • Joined: 22-August 14

Posted 22 August 2014 - 02:25 PM

Hello,

The topic of polymorphism has been a bit challenging, and although I just finished the chapter, exercises and all, I'm still a bit confused about the "AnimalTestDrive" example shown on page 207. Is that supposed to be a complete code? I tried to compile it unsuccessfully. Thanks in advance!



public class MyAnimalList {

private Animal[] animals = new Animal[5];
private int nextIndex = 0;

public void add ( Animal d) {

animals[nextIndex] = d;
if (nextIndex < animals.length) {
System.out.println("Animal added at " + nextIndex);
nextIndex++;
}
}
}

-----------------------------------------------------------------------------------------

public class AnimalTestDrive implements Animal {
public static void main(String[] args) {

MyAnimalList list = new MyAnimalList();
Dog a = new dog();
Cat b = new cat();
list.add(a);
list.add(B);
}
}
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users