Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Java serialization

807605Sep 19 2007 — edited Sep 19 2007
Assuming that the serializeBanana2() and the deserializeBanana2()
methods will correctly use Java serialization and given:



13. import java.io.*;

14. class Food {Food() { System.out.print(�1�); } }


15. class Fruit extends Food implements Serializable {
16. Fruit() { System.out.print(�2�); } }


17. public class Banana2 extends Fruit { int size = 42;
18. public static void main(String [] args) {
19. Banana2 b = new Banana2();
20. b.serializeBanana2(b); // assume correct serialization
21. b = b.deserializeBanana2(b); // assume correct
22. System.out.println(� restored �+ b.size + � �); }
23. // more Banana2 methods
24. }


What is the result?
A. 12 restored 42
B. 121 restored 42
C. 1212 restored 42

I think that the answer is A, but this is not correct. The concert answer is B. Does anybody know why is B correct?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 17 2007
Added on Sep 19 2007
1 comment
165 views