2009年2月17日 星期二

第148題

Given:
12. import java.io.*;
13. public class Forest implements Serializable{
14. private Tree tree = new Tree();
15. public static void main(String[] args){
16. Forest f = new Forest();
17. try{
18. FileOutputStream fs = new FileOutputStream("Forest.ser");
19. ObjectOutputStream os = new ObjectOutputStream(fs);
20. os.writeObject(f); os.close();
21. }catch(Exception ex){ex.printStackTrace();}
22. }}
23.
24. class Tree{}
What is the result?

A. Compilation fails.
B. An exception is thrown at runtime.
C. An instance of Forest is serialized.
D. An instance of Forest and an instance of Tree are both serialized.

答案:B
參考:10-5 多重串接

沒有留言:

張貼留言