• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Serialization question from K&B test

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
can anyone please explain me the working of the program given below.
why is the output :p cp instead of pc or pcpc?

Thanks in advance
[ January 17, 2007: Message edited by: Barry Gaunt ]
 
Ranch Hand
Posts: 381
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


//CardPlayer creation at 2 will call the super() and SOP at //1 will printed then SOP at //2.When the object is deserialized the objects no-args super constructors runs i.e. //1.If not zero argument constuctor exists then it throws a InvalidClassException.
 
Sarada Bikkina
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
why is the output not pcpc?i didnt not get any exception when the above program didnt have any constructors.can you be brief about the functionality?
 
Sanjeev Singh
Ranch Hand
Posts: 381
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

why is the output not pcpc?


Output as pcpc means you are running the constructor of the CardPlayer and initializing the state of the object which is just deserialized,so the state after the deserialization is lost.

i didnt not get any exception when the above program didnt have any constructors.


There must be a no-argument constructor or a default constructor else a runtime excetpion will generate.
[ January 17, 2007: Message edited by: Sanjeev Kumar Singh ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic