009-001-008
Private Modifier: Hiding Fields
Easy
Problem Description
Private Modifier: Hiding Fields
In this problem, you will create a program that implements a User class with a private name field hidden by the private modifier, reads a name from standard input, retrieves the field value via a getter method, and displays the result to standard output.
Learning Objective: Understand how to hide fields using the private modifier
Overview
Create a class using private fields and getter methods.
Specifications
- Create a
Userclass - Define private String field
name - Initialize via constructor
getName()method retrieves the name- In the Main class, read one line from standard input and use the getter to output
Input Format
name (string)
Output Format
User: name
Example
Input: Alice
Output: User: Alice
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