java fans:
If I extend a class which cann't be modified and didn't implements seriable. When I serialize my object, it didn't serialize the member variable inherited from parent class. Are there methods to serialize the object including the parent class without modifying the parent class?
Any help will be appreciated.
Please see the foll. snippet.
===============================================
import java.io.*;
class AA{
int x=11;
public void setx(int a){x=a;}
}
class BB extends AA implements Serializable{
int y=22;
public void sety(int a){y=a;}
}
public class test{
public static void main(
String args[]) {
BB b=new BB();
b.setx(33);
b.sety(44);
try{
FileOutputStream fos=new FileOutputStream("xxx.yyy");
ObjectOutputStream oos=new ObjectOutputStream(fos);
System.out.println("befor: "+b.x+" and "+b.y);//33,44
oos.writeObject(b);
oos.close();
fos.close();
}catch (IOException e){
System.out.println("error write obj");
}
try{
FileInputStream fis=new FileInputStream("xxx.yyy");
ObjectInputStream ois=new ObjectInputStream(fis);
BB sb=(BB)(ois.readObject());
System.out.println("after: "+sb.x+" and "+sb.y);//11,44
ois.close();
fis.close();
}catch (IOException e){
System.out.println("error read obj");
}catch(ClassNotFoundException e){
}
}
}