Monday, August 16, 2010

Serialization: Ford.java

Courtesy of Sun Web Learning Center


11. class Ford extends Car implements Serializable {
12.   Ford() { System.out.print("new Ford "); }
13. }
14.
15. class Car {
16.   Car() { System.out.print("new Car "); }
17. }

If you attempt to deserialize a properly serialized instance of Ford, what is the result?


A new Car
B new Ford
C new Car new Ford
D new Ford new Car
E Compilation fails.
F An exception is thrown at runtime.


A is correct. A superclass does not have to be serializable, but its constructor will run when a serializable subclass instance is deserialized.

No comments:

Post a Comment