-1
 private void writeObject(ObjectOutputStream o)
        throws IOException {  
        o.writeObject(propertyTwo);

        o.defaultWriteObject();  
  }

        private void readObject(ObjectInputStream o)
        throws IOException, ClassNotFoundException {

        propertyTwo = (String) o.readObject();
        o.defaultReadObject();
  }

Please explain how it serialize transient variable if we use defaultWriteObject and writeObject together?

MorganFreeFarm
  • 3,811
  • 8
  • 23
  • 46
  • You cant serialize transient variables. Please read [this post](https://stackoverflow.com/questions/20700530/why-use-the-transient-keyword-in-java) and accociated links – Laxman Jul 05 '17 at 08:02
  • @LaxmanChari You can, and this post shows exactly how. – user207421 Jul 05 '17 at 09:58

1 Answers1

0

It serializes it because you serialized it. Nothing to do with defaultWriteObject() or defaultReadObject() whatsoever. They won't serialize transient members. But you did.

user207421
  • 305,947
  • 44
  • 307
  • 483