“To allow suBTypes of non-serializable classes to be serialized, the subtype may assume responsibility for saving and restoring the state of the supertype's public, protected, and (if accessible) package fields. The subtype may assume this responsibility only if the class it extends has an accessible no-arg constrUCtor to initialize the class's state. It is an error to declare a class Serializable if this is not the case. The error will be detected at runtime. ” 也就是說,要為一個沒有實現Serializable接口的父類,編寫一個能夠序列化的子類要做兩件事情:
java.lang.Error: Unresolved compilation problem: Serializable cannot be resolved or is not a valid superinterface at Serial.SubC.<init>(SubC.java:15) at Serial.Test1.main(Test1.java:19) Exception in thread "main"