|
![]() |
![]() |
![]() |
![]() |
As we indicated at the beginning of the chapter, there is nothing to prevent a derived class being used as a base class. For example, we could derive a class Spaniel from the class Dog without any problem:
Start the Spaniel class off with this minimal code:
class Spaniel extends Dog { public Spaniel(String aName) { super(aName, "Spaniel"); } }
To try this out you can add a Spaniel object to the array theAnimals in the previous example, by changing the statement to:
Animal[] theAnimals = { new Dog("Rover", "Poodle"), JavaScript Editor Java Tutorials Free JavaScript Editor
→