Task 5 of 5 · 0 solved · 5 to go0%
You can read the problem, but answers are checked only for signed-in students. Sign in to answer →

Problem

7.5 Type checks and casting — capstone: the mixed zoo

Write a complete program with Animal, Dog (which adds fetch()) and Cat.

Read a count and that many pairs «kind name», store them all in one Animal[]. For each animal print fetch() if it is a dog, otherwise describe(). Finish by printing how many dogs there were.

For 3 then dog Rex cat Kit dog Bo:

Rex fetches
Kit is an animal
Bo fetches
2

fetch() is invisible through an Animal variable — check with instanceof, then cast.

time 1000 ms memory 256 Mb
Solution
Attempts: 0 A hint guides you to the fix — it never writes the code for you.
✦
Ready to check

Press «Submit» to run your code against the task's test cases — that is what sets your score. «AI review» is an optional second opinion: it reads your code — logic and style, not just the output — and suggests the next step without handing over the answer. It never changes your score.

Working…