009-001-008

Private Modifier: Hiding Fields

Easy

Problem Description

Private Modifier: Hiding Fields

Learning Objective: Understand how to hide fields using the private modifier

Overview

Create a class using private fields and getter methods.

Specifications

  • Create a User class
  • Define private String field name
  • Initialize via constructor
  • getName() method retrieves the name
  • Use getter in Main class to output

Output Format

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?