Assuming that the serializeBanana2() and the deserializeBanana2()
methods will correctly use Java serialization and given:
13. import java.io.*;
14. class Food {Food() { System.out.print(”1”); } }
15. class Fruit extends Food implements Serializable {
16. Fruit() { System.out.print(”2”); } }
17. public class Banana2 extends Fruit { int size = 42;
18. public static void main(String [] args) {
19. Banana2 b = new Banana2();
20. b.serializeBanana2(b); // assume correct serialization
21. b = b.deserializeBanana2(b); // assume correct
22. System.out.println(” restored “+ b.size + “ “); }
23. // more Banana2 methods
24. }
What is the result?
A. Compilation fails.
B. 1 restored 42
C. 12 restored 42
D. 121 restored 42
E. 1212 restored 42
F. An exception is thrown at runtime.答案D可以解释下么。。谢谢。。

解决方案 »

  1.   

    这个很容易呀,看看Serialization就懂了呀。
    兄弟,你到底看得什么书啊?
      

  2.   

    嘿嘿。z_lping(Schemer)又来了。。欢迎。。噼里啪啦那就解释下嘛。。最后的一个1哪来阿。。呵呵-_-..
      

  3.   

    我只贴一段:
    If you are a serializable class, but your superclass is NOT serializable, then any instance variables you INHERIT from that superclass will be reset to the values they were given during the original construction of the object. This is because the non-serializable class constructor WILL run!
      

  4.   

    If you are a serializable class, but your superclass is NOT serializable, then any instance variables you INHERIT from that superclass will be reset to the values they were given during the original construction of the object. This is because the non-serializable class constructor WILL run!
    ========================================================
    我看的书上怎么没有提 到类似这样的东西...
    郁闷...