Which of the following methods are defined by the Serializable interface?
Options :
A. readObject() and writeObject()
B. readExternal() and writeExternal()
C. serialize() and deserialize()
D. None of the Above
Answer : A [readObject() and writeObject()]
This is a API based question, one should not confuse with the options.
Classes that require special handling during the serialization and deserialization process must implement special methods with these exact signatures:
private void writeObject(java.io.ObjectOutputStream out)
throws IOException
private void readObject(java.io.ObjectInputStream in)
throws IOException, ClassNotFoundException;
private void readObjectNoData()
throws ObjectStreamException;
(Data taken from Java 1.6 API)
Q:Which of the following methods are defined by the Serializable interface?
ReplyDeleteAnswer : A [readObject() and writeObject()]
Should it not be: D. None of the Above
As Serializable is a marker interface.
Yes you are right. The right answer should be D.
ReplyDeleteBut if you want to handle serialization specially then one must implement read and write object.
Classes that require special handling during the serialization and deserialization process must implement special methods with these exact signatures.
private void writeObject(java.io.ObjectOutputStream out)
throws IOException
private void readObject(java.io.ObjectInputStream in)
throws IOException, ClassNotFoundException;