001package serialization.dynamicType;
002import java.io.*;
003
004public class Main {
005        public static void main(String args[])
006                        throws FileNotFoundException, IOException, ClassNotFoundException
007        {
008                ObjectOutputStream os
009                = new ObjectOutputStream (new FileOutputStream("out.dat"));
010                Entry eo = new Entry(1, new X0());
011                os.writeObject(eo);
012                os.close();
013
014                ObjectInputStream is
015                = new ObjectInputStream (new FileInputStream("out.dat"));
016                Entry ei = (Entry) is.readObject();
017                System.out.println(ei);
018                is.close();
019        }
020}
021
022class Entry implements Serializable {
023        private static final long serialVersionUID = 2008L;
024        private int i;
025        private X x;
026
027        public Entry(int i, X x) { this.i = i; this.x = x; }
028        public String toString() {
029                return "Entry(" + Integer.toString(i) + "," + x + ")";
030        }
031}
032
033interface X {
034        public String toString();
035}
036
037@SuppressWarnings("serial")
038class X0 implements X, Serializable {
039        public String toString() { return "X0"; }
040}
041
042class X1 implements X {
043        public String toString() { return "X1"; }
044}