I have a question regarding static & transient members:
Considering that "transient variables and static class members are ignored during the serialization and deserialization process" (page 427):
1) Why does my code output the static char type ('C' in this case)?
2) When I read my transient String, it still outputs null, why? "it is important to check for null values when reading from a serialized data stream. We rely on the instanceof operator to always return false for null values". (page 431)
Also, when I use a constructor without arguments, my code still outputs age 3 and type 'c'. But the explanation on page 432 states that "when the object is deserialized, no class constructor or default initializations are used"
1) Your static variable type is common to all instances of Animal. It is initialized the first time the class loads. After you create the first object, the type variable is assigned 'C'. Your class Animal is still there, so the class variable type is still there. It is not deserialized, but common to all instances of Animal and still has the value 'C'.
2) A transient instance variable is not deserialized. You check only if the deserialized object is instanceof Animal (not null). This line has nothing to do with the variable name.
3) The variable age is deserialized. No constructor is called. This information was hold in the file cat.html