Examveda

What will be the output of the following Java program?
import java.io.*;
class serialization 
{
    public static void main(String[] args) 
    {
        try 
        {
            Myclass object1 = new Myclass("Hello", -7, 2.1e10);
      FileOutputStream fos = new FileOutputStream("serial");
      ObjectOutputStream oos = new ObjectOutputStream(fos);
            oos.writeObject(object1);
            oos.flush();
            oos.close();
  }
  catch(Exception e) 
        {
      System.out.println("Serialization" + e);
            System.exit(0);
        }
  try  
        {
            Myclass object2;
      FileInputStream fis = new FileInputStream("serial");
      ObjectInputStream ois = new ObjectInputStream(fis);
            object2 = (Myclass)ois.readObject();
            ois.close();
      System.out.println(object2);		    	
  }
  catch (Exception e) 
        {
            System.out.print("deserialization" + e);
      System.exit(0);
  }
    }
}
class Myclass implements Serializable 
{
String s;
int i;
double d;
    Myclass (String s, int i, double d)
    {
  this.d = d;
  this.i = i;
  this.s = s;
}
}

A. s=Hello; i=-7; d=2.1E10

B. Hello; -7; 2.1E10

C. s; i; 2.1E10

D. Serialization

Answer: Option A


This Question Belongs to Java Program >> Java Serialization And Networking

Join The Discussion

Related Questions on Java Serialization and Networking

What is Java Serialization?

A. The process of converting an object into a byte stream

B. The process of converting a byte stream into an object

C. The process of converting an object into a text file

D. The process of converting a text file into an object