K & B
SCJP 5 page #493 "...remember that serialization is about instances, so static variables aren't serialized."
But that doesn't agree with this example. Can anyone shed light on this?
import java.io.*;
public class TestSer {
public static void main(
String[] args) {
SpecialSerial s = new SpecialSerial();
try {
ObjectOutputStream os = new ObjectOutputStream(
new FileOutputStream("myFile"));
os.writeObject(s); os.close();
System.out.print(++s.z + " ");
ObjectInputStream is = new ObjectInputStream(
new FileInputStream("myFile"));
SpecialSerial s2 = (SpecialSerial)is.readObject();
is.close();
System.out.println(s2.y + " " + s2.z);
} catch (Exception x) {System.out.println("exc"); }
}
}
class p implements Serializable {}
class SpecialSerial extends p {
transient int y = 7;
static int z = 9;
}