015-005-004

Polymorphism: Managing Child Classes with Parent Type Array

Medium

Problem Description

polymorphism: Managing Child Classes with Parent Type array

In this problem, you will create a program that defines Animal as a parent class, creates Dog and Cat as subclasses using inheritance and method overriding, stores them together in an Animal type array, and calls each object's speak() method using polymorphism, displaying the result to standard output.

Learning Objective: Understand how to uniformly handle different child class objects using a parent type array

Overview

Create Dog and Cat classes that extend Animal, store them in an Animal type array, and call each object's speak method.

Specifications

  • Animal class: speak() method (outputs "Animal speaks")
  • Dog class: override speak() (outputs "Woof!")
  • Cat class: override speak() (outputs "Meow!")
  • Store Dog and Cat in Animal type array

Output Format

Woof!
Meow!
Woof!

Test Cases

※ Output examples follow programming industry standards

Input:
Expected Output:
Woof!
Meow!
Woof!
Input:
Expected Output:
Woof!
Meow!
Woof!
Input:
Expected Output:
Woof!
Meow!
Woof!
Input:
Expected Output:
Woof!
Meow!
Woof!
❌ Some tests failed
❌ エラー発生

Your Solution

Current Mode: My Code
Animal.java🔒
Dog.java🔒
Cat.java🔒
Main.java🔒
4/6 ファイル93B
⚠️警告
  • No main method found
class Animal {
}
0 B / 5 MB

You have 3 free executions remaining