File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Related to Object Serialization

 
Ali Gohar
Ranch Hand
Posts: 572
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

The following code prints "pcp" whereas i think it should print "pcpc". Can anybody explains why it prints "pcp"?

 
Barry Gaunt
Ranch Hand
Posts: 7729
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How about you explaining why you think it prints that final "c"?
 
Burkhard Hassel
Ranch Hand
Posts: 1274
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Ali Gohar
Ranch Hand
Posts: 572
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 572
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks BH, i got that
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic