• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Serialization doubt

 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
source : http://www.javabeat.net/javabeat/scjp5/mocks/MockExam02.php



My doubt is howcome it prints "pcp"? I thought it will be "pc".
 
Ranch Hand
Posts: 383
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When you implement Serializable in a subclass whose superclass is not implementing Serializable, whenever you deserialized the subclass object only superclass constructor runs. So after line 1 you get "pc"(constructor runs) & after line 2 you get "p". So your output is "pcp". This example is from K & B book, chaper:6. They have given good description.


 
Ranch Hand
Posts: 278
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
when deserializing,
The class's contructor doesnt run again but parent class's does(if parent class not implementing serializable)
reply
    Bookmark Topic Watch Topic
  • New Topic