014-001-008
Inheritance and Field Inheritance
Medium
Problem Description
Inheritance and Field Inheritance
In this problem, you will create a program that defines a Vehicle class with a protected field brand, extends it with a Car class that includes setter and getter methods, reads the brand name from standard input, sets it via the setter, and displays the result to standard output.
Learning Objective: Understand how parent class fields are inherited by child classes
Overview
Create a program that uses parent class fields in a child class and accesses them through methods.
Specifications
- Define protected field
brandinVehicleclass Carclass extendsVehicleand adds setter and getter methods- Create
Carinstance inMainclass, read brand name from standard input, then set and output it
Input Format
brand name (single line)
Output Format
Brand: brand_name
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