SCJP 1.6版考題 142

出自 陳富國維基館
於 2013年3月30日 (六) 03:12 由 Ikk (對話 | 貢獻) 所做的修訂 (新頁面: Assuming that the serializeBanana() and the deserializeBanana() methods will correctly use Java serialization and given: 13. import java.io.*; 14. class Food implements Serializabl...)
(差異) ←上個修訂 | 最新修訂 (差異) | 下個修訂→ (差異)
前往: 導覽搜尋
Assuming that the serializeBanana() and the deserializeBanana()
methods will correctly use Java serialization and given:
13. import java.io.*;
14. class Food implements Serializable{int good = 3;}
15. class Fruit extends Food{int juice = 5;}
16. public class Banana extends Fruit{
17.   int yellow = 4;
18.   public static void main(String[] args) {
19.     Banana b = new Banana(); Banana b2 = new Banana();
20.     b.serializeBanana(b); //assume correct serialization
21.     b2 = b.deserializeBanana(); //assume correct
22.     System.out.println("restore " + b2.yellow + b2.juice + b2.good);
24.   }
25. //more Banana methods go here
50. }


What is the result?
 A. restore 400
 B. restore 403
 C. restore 453
 D. Compilation fails.
 E. An exception is thrown at runtime.

解答


Ans: C

解說: 物件的串流操作,serialize和deserialize可看做是將物件放入或取出一個磁帶