单项选择题
Assuming that the serializeBanana() and the deserializeBanana() methods will correctly use Java serialization and given:
import java.io.*;
class Food implemertts Serializable {int good = 3;}
class Fruit externds Food {int juice = 5;}
public class Banana extends Fruit {
int yellow = 4;
public static void main(String [] args) {
Banana b = new Banana(); Banana b2 = new Banana();
b.serializeBanana(b); // assume correct serialization
b2 = b.deserializeBanana(); // assume correct
System.out.println(”restore “+b2.yellow+ b2.juice+b2.good);
}
// more Banana methods go here
}
What is the result?()
A. restore 400
B. restore 403
C. restore 453
D. Compilation fails.
E. An exception is thrown at runtime.
相关考题
-
多项选择题
Whichthreeconcerningtheuseofthejava.io.Serializableinterfacearetrue?()
A. Objects from classes that use aggregation cannot be serialized.
B. Art 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 anddeserialization.
D. The values in fields with the transient modifier will NOT survive serialization anddeserialization.
E. It is legal to serialize an object of a type that has a supertype that does NOT implement java.io.Serializable. -
单项选择题
1. import java.io.*; 2. public class Foo implements Serializable { 3. public int x, y; 4. public Foo( int x, int y) { this.x = x; this.y = y; } 5. 6. private void writeObject( ObjectOutputStream s) 7. throws IOException { 8. s.writeInt(x); s.writeInt(y) 9. } 10. 11. private void readObject( ObjectInputStream s) 12. throws IOException, ClassNotFoundException { 13. 14. // insert code here 15. 16. } 17. } Which code, inserted at line 14, will allow this class to correctly serialize and deserialize?()
A. s.defaultReadObject();
B. this = s.defaultReadObject();
C. y = s.readInt(); x = s.readInt();
D. x = s.readInt(); y = s.readInt(); -
单项选择题
import java.io.*; public class Forest implements Serializable { private Tree tree = new Tree(); public static void main(String [] args) { Forest f= new Forest(); try { FileOutputStream fs = new FileOutputStream(”Forest.ser”); ObjectOutputStream os = new ObjectOutputStream(fs); os.writeObject(f); os.close(); } catch (Exception ex) { ex.printStackTrace(); } } } class Tree { } What is the result?()
A. Compilation fails.
B. An exception is thrown at runtime.
C. An instance of Forest is serialized.
D. A instance of Forest and an instance of Tree are both serialized.
