Hi,
Why description of question strictly says - "3. To serialize the object using the default behavior, you must call objectOutputStream.defaultWriteObject();. This will ensure that instance fields of Portfolio object are serialized."?
From https://docs.oracle.com/javase/8/docs/p ... .html#a861:
The class's writeObject method, if implemented, is responsible for saving the state of the class. Either ObjectOutputStream's defaultWriteObject or writeFields method must be called once (and only once) before writing any optional data that will be needed by the corresponding readObject method to restore the state of the object; even if no optional data is written, defaultWriteObject or writeFields must still be invoked once. If defaultWriteObject or writeFields is not invoked once prior to the writing of optional data (if any), then the behavior of instance deserialization is undefined in cases where the ObjectInputStream cannot resolve the class which defined the writeObject method in question.
For 4. point docs.oracle gives similar answer.
Best regards,
Aleksei
About Question enthuware.ocpjp.v8.2.1390 :
Moderators: Site Manager, fjwalraven
-
- Posts: 6
- Joined: Wed Jun 22, 2016 8:06 am
- Contact:
-
- Site Admin
- Posts: 10388
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1390 :
You are right. It should say defaultWriteObject() or writeFields. Fixed.
thank you for your feedback!
thank you for your feedback!
Who is online
Users browsing this forum: No registered users and 5 guests