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

Problem

7.4 Polymorphism — capstone: a mixed array

Write a complete program with Animal and two subclasses Dog and Cat, each overriding describe().

Read a count n, then n pairs of a kind (dog or cat) and a name. Store them all in one Animal[] array.

Print each animal's description in order, then print how many of them are dogs.

For 3 then dog Rex cat Kit dog Bo:

Rex is a dog
Kit is a cat
Bo is a dog
2

The array type is Animal[], yet each element runs its own describe() — that is polymorphism at work.

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.

Next module →
Working…