Answer Posted / bharat shivram
import java.io.*;
public class SerializationDemo {
public static void main(String args[]) {
// Object serialization
try {
MyClass object1 = new MyClass("Hello", -7, 2.7e10);
System.out.println("object1: " + object1);
FileOutputStream fos = new FileOutputStream("serial");
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeObject(object1);
oos.flush();
oos.close();
}
catch(Exception e) {
System.out.println("Exception during serialization: " + e);
System.exit(0);
}
| Is This Answer Correct ? | 3 Yes | 0 No |
Post New Answer View All Answers
What are abstract classes and anonymous classes?
How does system arraycopy work in java?
What is a functional interface?
Is integer a class?
What is singleton class in ruby?
How many functional interfaces does java 8 have?
What is bufferedwriter?
Can a static member function access member variable of an object?
What initialize variables?
What is the super void?
What is flush buffer?
How many types of operators are there?
What is a buffer in java?
What an i/o filter?
Can you achieve runtime polymorphism by data members?