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
ImmutablePointclass - Define private final int fields
xandy - Set values via constructor
- Define only getters (no setters)
- In the Main class, read
xandyfrom 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