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

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