Hello
With reference to question 36 in chapter 9 of the OCP Oracle Certified Professional
Java SE 17 Developer Practice Tests: Exam 1Z0-829 (English Edition) book (Kindle edition), shown below.
In this question, an instance of Cereal has been serialized to disk, with the source object having a name value of CornLoops and sugar value of 5. What is the value of name and sugar after this object has been read from disk using the ObjectInputStream's readObject() method?
The question seems to start with a fact: "
In this question, an instance of `Cereal` has been serialized to disk...". The
Bowl record does not implement
Serializable, which means the
bowl instance field must have been
null (otherwise the initial part of the question is incorrect).
Given that the
bowl instance field must have been
null during serialisation, we are able to deserialize the object, making option B correct. Following are all options available for completeness.
A. CaptainPebbles and 10
B. CornLoops and 0
C. SugarPops and 10
D. SugarPops and 2
E. CornLoops and -1
F. None of the above
Any thoughts?