009-001-012

Private Modifier: Immutable Object

Medium

Problem Description

Private Modifier: Immutable Object

In this problem, you will create a program that implements an ImmutablePoint class with private final fields and getters only, reads coordinates from standard input, and displays them.

Learning Objective: Create immutable objects that cannot be changed after creation

Overview

Create an immutable class with no setters.

Specifications

  • Create an ImmutablePoint class
  • Define private final int fields x and y
  • Set values via constructor
  • Define only getters (no setters)
  • In the Main class, read x and y from standard input and print the coordinate

Input Format

x
y
  • Line 1: integer x
  • Line 2: integer y

Output Format

Point: (x, y)

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