So I was studying serialization for OCJP exam from the book written by Jeanne Boyarsky and Scott Selikoff when on page number 448 I found a question :
Why shouldn't every class be marked Serializable ?
One of the answers said : The compiler will throw an exception if certain classes are marked Serializable
I thought this was a correct answer but according to the book this is not a correct I don't understand why, check this code:
This code throws a java.io.NotSerializableException when executed. Here the MyClass class if marked Serializable will throw an exception so the option should be correct.
Next although I understood serializability I did not understand one thing the book said. What does this mean ?
"Java will call the constructor for the first non-serializable no-arguments parent class during deserialization, skipping any constructors and default initializations for serializable classes in between"
Can someone explain this sentence possibly with an example because it seems too difficult to understand for me.
By the way a big thank you to this forum and all the awesome people in it. It has proven to be life saviour for me in clearing all my doubts....