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
In this problem, you will create a program that defines an Animal class with protected fields (name, age) and a Dog subclass that inherits from it, directly accesses the parent class's protected fields, and displays the animal information to standard output.
Read the animal name and age as input, create an Animal instance, then use the Dog class to access its protected fields and print the output in the specified format.
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
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