1z0-829 Exam QuestionsBrowse all questions from this exam

1z0-829 Exam - Question 41


Given the Product class:

and the Shop class:

What is the result?

Show Answer
Correct Answer: B

The Product class implements Serializable, and the price field is marked as transient, meaning it won't be serialized. When the Product object is deserialized, the readObject method in the Product class sets the price field to the static averagePrice value, which is 2.99. Hence, when the toString method is called, it returns the description 'Cookie', the price field which has been set to 2.99, and the static averagePrice which is also 2.99. This means the printed output would be 'Cookie 2.99 2.99'.

Discussion

2 comments
Sign in to comment
supersquaxOption: B
Jan 31, 2024

B correct, verified in online compiler!

xplorerpjOption: B
Jun 25, 2024

B is correct