Search This Blog

Sunday, January 30, 2011

Question 18

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)
Question 18SocialTwist Tell-a-Friend

2 comments:

  1. Q:Which of the following methods are defined by the Serializable interface?

    Answer : A [readObject() and writeObject()]

    Should it not be: D. None of the Above

    As Serializable is a marker interface.

    ReplyDelete
  2. Yes you are right. The right answer should be D.

    But 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;

    ReplyDelete