Serialization
following is an excerpt from our very own Kathy. its not exactly the way it is in her book. my que is in the code itself. its commented .
import java.io.*;
class SuperNotSerial
{
public static void main(String[] ar)
{
Dog d=new Dog(100,"fido");
Dog d2=null;
System.out.println("before: "+d.name+" "+d.weight);
try
{
FileOutputStream fs=new FileOutputStream("test.txt");
ObjectOutputStream os=new ObjectOutputStream(fs);
os.writeObject(d);
os.close();
}catch(Exception e){}
try
{
FileInputStream fis=new FileInputStream("text.txt");
ObjectInputStream ois=new ObjectInputStream(fis);
d2=(Dog)ois.readObject();
System.out.println("after2: "+d2.name+" "+d2.weight);//this line never gets printed.y?
ois.close();
}catch(Exception e){}
System.out.println("after: "+d2.name+" "+d2.weight);
}
}
class Dog extends Animal implements Serializable
{
String name;
Dog(int w,String name)
{
this.name=name;
this.weight=w;
}
}
class Animal
{
int weight=45;
}

