015-004-008

Polymorphism with ArrayList

Medium

Problem Description

polymorphism with ArrayList

In this problem, you will create a program that defines Dog, Cat, and Bird subclasses extending Animal, overrides the speak() method in each subclass, stores instances in an ArrayList<Animal>, and displays each animal's sound to standard output by calling speak() in a loop.

Learning Objective: Understand how to store different child class objects in parent class type ArrayList

Overview

Create a program that stores different child class instances in parent class type ArrayList and utilizes polymorphism.

Specifications

  • Define Animal class and its subclasses (Dog, Cat, Bird)
  • override speak() method in each class
  • Add various animals to ArrayList and output sounds in loop

Output Format

Woof!
Meow!
Chirp!

Ready to Try Running Code?

Log in to access the code editor and execute your solutions for this problem.

Don't have an account?

Sign Up