hi,
why the following code works if it is said about the externalization that,
if we use exter. then we need to take care of the parent object as well on our own using getter methods for getting parameters or by direct access (if it's allowed) if the parent doesn't implement exter.
class a {
String n = "class a";
void f1() { S.o.p("a.f1()"); }
}
class b extends a implementes Externalizable {
String n = "class b";
void f2() { S.o.p("b.f2()"); }
public void writeExternal(ObjectOutput out) throws IOException {
out.writeObject(n);
}
public void readExternal(ObjectInput in ) throws IOException , ClassNotFoundException {
n = (String)in.readObject();
}
static void main(String[] s) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(new b());
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
ObjectInputStream ois = new ObjectInputStream(bais);
b newB = (b)ois.readObject();
b.f1();
b.f2();
}
}
regards
maulin