Forums Register Login

Serailaizable code example

+Pie Number of slices to send: Send
Sir/ Madam

Please find below a piece of code:




The output according to the book is that "exc" will be printed. Please explain why?

Regards
Mansukhdeep
+Pie Number of slices to send: Send
When you want to serialize an instance, remember that all of its instance variables, except those marked as transient, have to be serializable. Which means that these variables have to implement the Serializable interface. Do you see what I mean ?
+Pie Number of slices to send: Send
To know details about Exceptions, try to print Stack Trace.
+Pie Number of slices to send: Send
 

Christophe Verré wrote:When you want to serialize an instance, remember that all of its instance variables, except those marked as transient, have to be serializable. Which means that these variables have to implement the Serializable interface. Do you see what I mean ?



Agreed Christophe

But since the instant private Keyboard k = new KeyBoard() is present inside the Computer class which is implenting Serializable interface, doesn't that make all its instances inside it automatically Serializable? Kindly elaborate with reference to this code example.

Regards
Mansukhdeep
+Pie Number of slices to send: Send
Just because you put a KeyBoard in your Computer doesn't make the KeyBoard Serializable. It really must implement Serializable itself for that.
+Pie Number of slices to send: Send
as Rob said, instance variables are not automatically serializable. You have to take care of this.
Yes, of course, and I accept that blame. In fact, i covet that blame. As does this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 643 times.
Similar Threads
Doubt in Serialization
Serialization
serialization doubt
KB queston pg 5o1
Serialization
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 04:30:15.