Help coderanch get a
new server
by contributing to the fundraiser
  • 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

A possible typo in question (or answer) 36 in chapter 9 (OCP 17 - Practice Tests)

 
Ranch Hand
Posts: 72
5
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Saloon Keeper
Posts: 15659
367
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you want our thoughts, you'll have to share more context. We don't know what the Cereal class (or any of its components) looks like, nor what the question is asking.
 
Albert Attard
Ranch Hand
Posts: 72
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for your reply.

I made the wrong assumption that everyone in this chat group has the book.

This is the Cereal class.



I have added the setters and toString() methods as these were omitted, I believe for brevity.

The following code shows how to reproduce this.



The above example works and prints the output matching option B.
 
Stephan van Hulst
Saloon Keeper
Posts: 15659
367
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay, so what's the problem?
 
Albert Attard
Ranch Hand
Posts: 72
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I believe the answer is incorrect.

The book says option F is the correct answer, while I believe it should be option B.
 
author & internet detective
Posts: 41945
911
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok that one gets TWO cows. Added to errata.

You broke our question . Seriously though, you are right. We were not assuming it would be null. But then it fails on writing rather than reading and that breaks the question.
 
She's brilliant. She can see what can be and is not limited to what is. And she knows this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/t/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic