This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
I think the 121 is because the constructor calls. When you have Banana b=new Banana(); It calls its parent constructors that's why you have 12. Then when you b=b.deserialize(b); it calls its parent constructor that is not serializable which gives you the last 1.
HI, The key point here to note here is that the constructors are not called while deserializing the object.While serializing the object,the constructors will be called. So while serializing the b,superclass constructors are called..output is 1 2.then while deserilasing the object,since the food is not serialised,its constructor is called once again and the output is 1 and finally restore and 42.