2009年2月17日 星期二

第152題

Which three statements concerning the use of the java.io.Serializable interface are true? (Choose three.)

A. Objects from classes that use aggregation cannot be serialized.
B. An object serialized on one JVM can be successfully deserialized on a different JVM.
C. The values in fields with the volatile modifier will NOT survive serialization and deserialization.
D. The values in fields with the transient modifier will NOT survive serialization and deserialization.
E. It is legal to serialize an object of a type that has a supertype that does NOT implement java.io.Serializable.

答案:BDE
參考:10-5-2 ObjectInputStream與ObjectOutputStream類別
-----------------------------------------------------------------------------------------
B. An object serialized on one JVM can be successfully deserialized on a different JVM.
如果一個物件在一個jvm上做序列化就可以在另一個jvm上做反序列化
ex:執行一個程式產生一個新的jvm,這個程式是把物件寫入檔案中...
再開一個程式把產生另一個jvm,反序列化就是檔案取出
D. The values in fields with the transient modifier will NOT survive serialization and deserialization.
屬性加上transient的修飾詞 在序列化過程中就不會保留它的值,因此在做反序列化時

會取出系統預設的初始值,換句話說不會保留原有的值
E. It is legal to serialize an object of a type that has a supertype that does NOT implement java.io.Serializable.
如果現在要序列化一個物件,該物件所屬類別的父類別不需要實做java.io.Serializable,

但該物件是需要實做

沒有留言:

張貼留言