014-004-003

Protected Modifier: Animal Inheritance Hierarchy

Hard

Problem Description

Protected Modifier: Animal Inheritance Hierarchy

Learning Objective: Define fields accessible from subclasses using protected modifier

Create an animal inheritance hierarchy. Use protected fields to access parent state from subclasses.

Input

Line 1: Animal name (string)
Line 2: Age (integer)

Output

Animal created: [name], age [age]
Dog info: [name] is a [age] year old dog
Protected access verified: success

Test Cases

※ Output examples follow programming industry standards

Input:
Pochi
3
Expected Output:
Animal created: Pochi, age 3
Dog info: Pochi is a 3 year old dog
Protected access verified: success
Input:
Max
0
Expected Output:
Animal created: Max, age 0
Dog info: Max is a 0 year old dog
Protected access verified: success
Input:
Buddy
10
Expected Output:
Animal created: Buddy, age 10
Dog info: Buddy is a 10 year old dog
Protected access verified: success
❌ Some tests failed
❌ エラー発生

Your Solution

Current Mode: My Code
import java.util.Scanner;

public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
// Write your code here

sc.close();
}
}
0 B / 5 MB

You have 9 free executions remaining