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
how to prepare for IT Officers Interview in Banks
What are abstract methods in java?
What is outofmemoryerror in java?
What is set and get methods in java?
What is ternary operator?
Can a constructor call the constructor of parent class?
How do I stop concurrentmodificationexception?
What is a package in java? List down various advantages of packages.
What is the use of conditional statement?
what is meant by abstract class?
What is the basic concept of java?
Can inner class be public in java?
What is an class?
What is the difference between the font and fontmetrics classes in java programming?
Is null keyword in java?