Seetharaman Venkatasamy wrote:serialize and deserialize should be in different class.
note: please search first. this kind of topics discussed many times here in javaranch 
sorry i did't got what you want to say...
but the complete code is like...
import java.io.*;
public class A{
public static void main(String arg[]){
B b=new B();
b.x1=7;b.x2=7;b.x3=7;//1
try{
FileOutputStream fs=new FileOutputStream("a.txt");
ObjectOutputStream os=new ObjectOutputStream(fs);
os.writeObject(b);
os.close();
}
catch(Exception e){}
try{
FileInputStream fi=new FileInputStream("a.txt");
ObjectInputStream oi=new ObjectInputStream(fi);
b=(B)oi.readObject();
}
catch(Exception e){}
System.out.println(b.x1+""+b.x2+""+b.x3);
}
}
class B implements Serializable{
static int x1=0;
volatile int x2=0;
transient int x3=0;
}
after running the output is x1=7,x2=7,x3=0