• 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 all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

OCP Java SE 8 Programmer II Study Guide: a question about serialization

claude lepere
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good evening, Jeanne.

ISBN: 978-1-119-06790-0
ISBN: 978-1-119-06788-7 (ebk.)
ISBN: 978-1-119-06789-4 (ebk.)

p. 432 in the middle of the page: [Animal [name=null, age=0, type=P], Animal [name=null, age=0, type=P]]

This is the output I get if "this.type = 'Q';" is present in the constructor "Animal()" and if "this.type = type;" is also present in the constructor "Animal(String name, int age, char type)"
but, char type is static in the class "Animal", both statements strictly speaking should not be present in the constructors.
If I comment out both statements, "type=P" in the output is now "type=C", which is correct because as the static field "type" is not serialized, the value of "type" is not present in the returned object from the deserialization but comes from a new instanciation of the class.

My question is: since the field "type" is not serialized, where does the value 'P' come from then?

Please, excuse my low level of English.

Thanks in advance for your answer. Claude Lepère
He was expelled for perverse baking experiments. This tiny ad is a model student:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!