import java.io.*; class Data implements Serializable { int n; Data next; public Data(int n) { this.n = n; } } public class Serial { public static void main(String[] args) throws ClassNotFoundException, IOException { Data d1 = new Data(1); d1.next = new Data(2); d1.next.next = d1; ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream("d.out")); out.writeObject(d1); out.close(); ObjectInputStream in = new ObjectInputStream(new FileInputStream("d.out")); Data d2 = (Data)in.readObject(); in.close(); System.out.println(d2.n + ", next " + d2.next.n + ", and back " + d2.next.next.n); } }