I have the following code:
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 + " "); ...(1)
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 SpecialSerial implements Serializable {
transient int y = 7;
static int z = 9;
}
Now when i ran the code, the output was "10 0 10". But why is it "10 0 10" and not "10 0 0"? I mean when i deserialized the object, y and z (being transient and static resp) should have returned as 7 and 9, which are the default values (please correct me at this point cause i think that the values the object gets after the deserialization are default values). And what does the syntax "++object.var" means(refer (1)). Is it the same as "Object var++" ie, is "++s.z" same as "s.z++"?