Courseiva
Java I/O API and Securing ApplicationshardMultiple ChoiceObjective-mapped

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

A class implements Serializable but the developer wants to completely prevent deserialization of its instances. Which approach accomplishes this?

⚠ Common exam trap

Test-takers frequently confuse readResolve() with readObject(), thinking that returning null from readResolve() prevents deserialization, when in fact readResolve() runs after the object is already created, so it does not stop the deserialization process itself.

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

Override readObject() to throw an InvalidClassException.

Overriding readObject() to throw an InvalidClassException (or any exception) prevents the deserialization mechanism from completing. When an ObjectInputStream calls readObject() on a class that defines its own readObject() method, that custom method is invoked instead of the default deserialization. Throwing an exception inside readObject() aborts the deserialization process, effectively blocking the reconstruction of the instance.

Answer analysis

Option-by-option breakdown

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

  • Override readResolve() to return a null.

    Why it's wrong here

    readResolve() is called after deserialization; it cannot prevent the process from starting.

  • Override readObject() to throw an InvalidClassException.

    Why this is correct

    This causes deserialization to fail immediately.

  • Override writeObject() to encrypt the object.

    Why it's wrong here

    Encrypting during serialization doesn't prevent deserialization; the object can still be decrypted.

  • Override writeReplace() to throw an exception.

    Why it's wrong here

    writeReplace() is invoked during serialization, not deserialization.

About these practice questions

Courseiva writes every 1Z0-829 question from scratch — 513 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or 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.