1Z0-830 practice question 3 of 25

What interface does a class need to implement to be eligible for serialization?

Full set: 116 questions
Answer options
A:

A. Serializable

Correct answer
B:

B. Cloneable

C:

C. ObjectOutputStream

D:

D. DataOutputStream

Correct Answer:
A. A. Serializable
Explanation

To be eligible for Java's object serialization, a class must implement the java.io.Serializable interface. This is a marker interface, meaning it does not contain any methods that need to be implemented. Its presence simply signals to the Java Virtual Machine's serialization mechanism that instances of the class can be converted into a byte stream and later reconstructed.

Why Incorrect

B. The Cloneable interface is a marker interface indicating that it is legal for Object.clone() to make a field-for-field copy of instances of that class.
C. ObjectOutputStream is a concrete class used to write serialized objects to a stream; it is not an interface implemented by the objects being serialized.
D. DataOutputStream is a class for writing primitive Java data types to an output stream, not for serializing entire objects.

References

1. Oracle Corporation. (2023). Serializable (Java SE 21 & JDK 21). Java Platform, Standard Edition 21 API Specification. Retrieved from https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/io/Serializable.html. (The first sentence of the interface description clarifies its purpose).

2. Oracle Corporation. (2023). Object Serialization (The Java™ Tutorials > Essential Java Classes > Basic I/O). Retrieved from https://docs.oracle.com/javase/tutorial/essential/io/objectstreams.html. (The section "Making a Class Serializable" explicitly states the requirement to implement java.io.Serializable).

Scroll to Top