| Author |
Related to Object Serialization
|
Ali Gohar
Ranch Hand
Joined: Mar 18, 2004
Posts: 572
|
|
Hi, The following code prints "pcp" whereas i think it should print "pcpc". Can anybody explains why it prints "pcp"?
|
 |
Barry Gaunt
Ranch Hand
Joined: Aug 03, 2002
Posts: 7729
|
|
|
How about you explaining why you think it prints that final "c"?
|
Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
|
 |
Burkhard Hassel
Ranch Hand
Joined: Aug 25, 2006
Posts: 1274
|
|
Hi Ali,
i think it should print "pcpc"
First think about, what Barry said, but if you don't get it, see below the "spoiler". spoiler The last c will not print, because in deserialization, the constructors of classes implementing Serializable will not run. Only constructors of superclasses not implementing Serializable will run. If you have the K&B book, you can look it up on pages 453 and the following. Yours, Bu. [ October 06, 2006: Message edited by: Burkhard Hassel ]
|
all events occur in real time
|
 |
Ali Gohar
Ranch Hand
Joined: Mar 18, 2004
Posts: 572
|
|
I think that when it will read the object from serialized file, it will create new CardPlayer() and will then set the values, so if its true then again "pc" should be printed making "pcpc", but i know i am wrong Can you explain why?
|
 |
Ali Gohar
Ranch Hand
Joined: Mar 18, 2004
Posts: 572
|
|
|
Thanks BH, i got that
|
 |
 |
|
|
subject: Related to Object Serialization
|
|
|