015-001-004

Polymorphism Basics: Animal Class

Easy

Problem Description

polymorphism Basics: Animal class

In this problem, you will create a program that implements polymorphism by creating Dog and Cat classes that extend Animal, assigns child class objects to an Animal type variable, calls overridden getType() and getSound() methods, and displays the result to standard output.

Learning Objective: Understand polymorphism handling child class objects with parent class reference

Create an Animal class and Dog/Cat subclasses that inherit from it. Read the animal type ("Dog" or "Cat") and name from input, assign the child class object to an Animal type variable, and verify that the overridden methods are called correctly.

Input

Line 1: Animal type ("Dog" or "Cat")
Line 2: Name (string)

Output

Animal: [name]
Type: [Dog/Cat]
Sound: [Woof/Meow]
```java

## Examples

### Example 1: Dog case
Input:
```java
Dog
Pochi
```java
Output:
```java
Animal: Pochi
Type: Dog
Sound: Woof
```java

### Example 2: Cat case
Input:
```java
Cat
Tama
```java
Output:
```java
Animal: Tama
Type: Cat
Sound: Meow
```java

### Example 3: Boundary (single character name)
Input:
```java
Dog
A
```java
Output:
```java
Animal: A
Type: Dog
Sound: Woof

Test Cases

※ Output examples follow programming industry standards

Input:
Dog
Pochi
Expected Output:
Animal: Pochi
Type: Dog
Sound: Woof
Input:
Cat
Tama
Expected Output:
Animal: Tama
Type: Cat
Sound: Meow
Input:
Dog
A
Expected Output:
Animal: A
Type: Dog
Sound: Woof
Input:
Dog
Pochi
Expected Output:
Animal: Pochi
Type: Dog
Sound: Woof
❌ Some tests failed
❌ エラー発生

Your Solution

Current Mode: My Code
Animal.java🔒
Dog.java🔒
Cat.java🔒
Solution.java🔒
4/6 ファイル205B
⚠️警告
  • No main method found
import java.util.Scanner;

class Animal {
}
0 B / 5 MB

You have 7 free executions remaining