Home » JAVA Programming » Serialization » Question
  1. What is the output of this program?
    import java.io.*;
    public class serialization_Example
    {
    public static void main(String[] args)
    {
    try
    {
    Newclass obj1 = new Newclass("InterviewMania", -10, 3.2e20);
    FileOutputStream fos = new FileOutputStream("serial");
    ObjectOutputStream oos = new ObjectOutputStream(fos);
    oos.writeObject(obj1);
    oos.flush();
    oos.close();
    }
    catch(Exception e)
    {
    System.out.println("Serialization" + e);
    System.exit(0);
    }
    try
    {
    Newclass obj2;
    FileInputStream fis = new FileInputStream("serial");
    ObjectInputStream ois = new ObjectInputStream(fis);
    obj2 = (Newclass)ois.readObject();
    ois.close();
    System.out.println(obj2);
    }
    catch (Exception e)
    {
    System.out.print("deserialization" + e);
    System.exit(0);
    }
    }
    }
    class Newclass implements Serializable
    {
    String str;
    int k;
    double p;
    Newclass (String str, int k, double p)
    {
    this.p = p;
    this.k = k;
    this.str = str;
    }
    }
    1. Newclass@776ec8df
    2. InterviewMania
    3. Interview
    4. Mania
    5. None of these
Correct Option: A

Myclass@776ec8df



Your comments will be displayed only after manual approval.