My source is
Sun Certification Sample
I know serialization is not in the exam anymore but I want to understand whether the reported answer is right.
The reported answer is 0 7 0 but my understanding is that it should be 7 7 0 as the value of the static variable is going to remain unaffected by serialization/unserialization as it is not part of serialized object. Is it an error in the question or is there a way of interpreting the question so the given answer makes sense? Incidentally, I have included the serialization/deserialization code as the original just stated:
4) Given:
2. import java.io.*;
3. public class Network {
4. public static void main(
String[] args) {
5. Traveler t = new Traveler();
6. t.x1 = 7; t.x2 = 7; t.x3 = 7;
7. // serialize t then deserialize t
8. System.out.println(t.x1 + " " + t.x2 + " " + t.x3);
9. }
10. }
11. class Traveler implements Serializable {
12. static int x1 = 0;
13. volatile int x2 = 0;
14. transient int x3 = 0;
15. }
If, on line 7, t is successfully serialized and then deserialized, what is the result?