I was just dabbling in the serialization code given in K. Sierra book on SCJP.
I ran the following code snippet
Now according to the book, as the collar class has not implemented serializable interface, to bypass that I created a transient object of type collar in dog class. According to the book, such an action will compile the code, but at runtime will throw a NullPointerException as the state of the 'thecollar' object wasn't saved. Now I know I'm missing something in the code, but can't get hold of it.. probably just too tired today.
I hope someone can point out. And I'm just a newbie in java, So please don't tell me how stupid question it was --> I already know that
since transient object can not be serialized. that object wont save as binary in to file.
when you deserialize the object(dog) you dont get the object which stored in c filed of dog. so JVM assign null to it.
note: you dont get any exception till now.
but when you call any method on c here after obviously you get NPE.
I'm sorry, I don't see a question. Or rather, I see a set of posts which contain various statements which might be questions which might still be unanswered. So, could you summarize the action so far and ask a clear question? And since there's various code in the thread now, specify which code you're talking about?
(By the way the easiest way to post indented code is to copy the indented code from your text editor and paste it here, inside the code tags.)