001package serialization;
002import java.io.*;
003
004class Person2 implements Externalizable {
005        private static final long serialVersionUID = 2008L;
006        private String name = ""; private int age = 0;
007        public Person2() { }
008        public Person2(String name, int age) { this.name = name; this.age = age;}
009        public String getName() { return name; }
010        public int getAge() { return age; }
011        public String toString() {return "Name: " + name + " Age: " + Integer.toString(age);}
012
013        public void writeExternal(ObjectOutput out)
014                        throws IOException
015        {
016                out.writeObject(name);
017                out.writeInt(age);
018        }
019        public void readExternal(ObjectInput in)
020                        throws IOException, ClassNotFoundException
021        {
022                name = (String) in.readObject();
023                age = in.readInt();
024        }
025}