Socket Programming Question:
Download Questions PDF

How to serialize a custom class?

Answer:

In this example, we create a custom class, UserInfo which is shown in Code Sample. To make it serializable, it implements the Serializable interface.

Code Sample 3: UserInfo.java

mport java.io.*;
import java.util.*;

public class
UserInfo implements Serializable {
String name = null;

public UserInfo(String name) {
this.name = name;
}

public void printInfo() {
System.out.println("The name is: "+name);
}
}

Download Socket Programming Interview Questions And Answers PDF

Previous QuestionNext Question
How to create a class that creates a instance of the UserInfo class and writes the object to an output stream?Shows how to read a serialized object and print its information?