Inheritance
Inheritance
- superclasses and subclasses
- super()
- overriding methods
- Object
Monster.java
VampireBat.java
MuppetMonster.java
MonsterTestHarness.java
Pet.java
Cat.java
Dog.java
Budgie.java
PetHarness.java
Deitel 9-10
Classwork
A zoo is developing an educational safari game with various animals. You will write classes representing Elephants and Camels.
Part A
Think through common characteristics of animals, and write a class ZooAnimal.
Give ZooAnimal at least two instance variables of different types (protected)
representing information we would need to know about any animal. (hint:
type of animal would be a terrible choice -- which class we use will
take care of that)
Give ZooAnimal at least two methods representing behaviors -- things
that all
animals do, and most do the same way. These can simply print out a
message stating what the animal is doing.
Include at least one parameterized constructor.
Part B
Create classes Elephant and Camel both of which extend ZooAnimal. In each,
include a default constructor that calls the parameterized superclass
constructor, passing it appropriate value(s).
To one class (of Elephant and Camel), add another instance variable, specific to that type of animal.
To one, add another behavior specific to that type of animal.
In one, override a behavior from ZooAnimal so that it happens in a way specific to this animal.
Part C
Create a test harness for the animal classes. In a main create an instance for each of the classes, and demonstrate what each can do
(that is, call all the behavior methods and set all the variables).
[EC] Create another animal class inheriting from Elephant or Camel (so a
specific kind of elephant or kind of camel -- these need not be biologically
accurate),
and either add an instance variable or add or override a method. This class should also be tested in the harness.