Courseiva
Java I/O API and Securing ApplicationsmediumDrag & DropObjective-mapped

1Z0-829 Java I/O API and Securing Applications Practice Question

Order the steps to create an immutable class in Java.

Drag steps to the numbered slots on the right, or tap a step then tap a slot.

Steps
Order
1Step 1
2Step 2
3Step 3
4Step 4
5Step 5

Answer choices

Why each option matters

Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.

Correct answer & explanation

Step 1: Declare the class as final. Step 2: Declare all fields as private and final. Step 3: Provide a constructor that initializes all fields (with defensive copying for mutable fields). Step 4: Do not define any setter methods.

Immutability requires no way to change object state after construction. Defensive copying prevents internal state from being altered.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • Step 1: Declare the class as final. Step 2: Declare all fields as private and final. Step 3: Provide a constructor that initializes all fields (with defensive copying for mutable fields). Step 4: Do not define any setter methods.

    Why this is correct

    This is correct because declaring the class final prevents subclassing, making fields final ensures they cannot be reassigned, a constructor initializes all state (with defensive copying for mutable objects), and no setters prevents external modification.

  • Step 1: Declare all fields as private and final. Step 2: Provide a constructor that initializes all fields. Step 3: Declare the class as final. Step 4: Do not define any setter methods.

    Why it's wrong here

    This is incorrect because the class should be declared final first to prevent subclassing, which could add mutable behavior or override methods. Declaring fields final before ensuring the class is final leaves the possibility of a subclass adding setters or modifying behavior.

  • Step 1: Provide a constructor that initializes all fields. Step 2: Declare all fields as private and final. Step 3: Declare the class as final. Step 4: Do not define any setter methods.

    Why it's wrong here

    This is incorrect because fields should be declared as final before the constructor is defined; otherwise, the constructor cannot assign to final fields legally. Also, the class should be final to prevent subclassing.

  • Step 1: Do not define any setter methods. Step 2: Declare the class as final. Step 3: Declare all fields as private and final. Step 4: Provide a constructor that initializes all fields.

    Why it's wrong here

    This is incorrect because a constructor is essential to set initial values; without it, the object cannot be created properly. Also, declaring no setters before the class and fields are set up is meaningless.

About these practice questions

This 1Z0-829 question is part of Courseiva's 513-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

JA

Written by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

This 1Z0-829 practice question is part of Courseiva's free Oracle certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the 1Z0-829 exam.