Interview Questions

In Code Sample. How to serialize a custom class ?

An Introduction to Socket Programming


(Continued from previous question...)

In Code Sample. How to serialize a custom class ?

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);
   }
}

(Continued on next question...)

Other Interview Questions