Oracle Certified Professional Java Se 11 Developer · Free Practice Question Hard

Question 71

Question ID: UKOCP30884


Given code:


There is full permission to list/create/delete files and directories in C:.


What is the result?

  • A Runtime Exception
  • B 1
  • C 2
  • D 3
Reveal correct answer

Correct answer: D

Explanation

UKOCP30884:

Counter class implements Serializable, hence objects of Counter class can be serialized using ObjectOutputStream.


State of transient and static fields are not persisted.


While de-serializing, transient fields are initialized to default values (null for reference type and respective Zeros for primitive types) and static fields refer to current value.


In this case, count is static, so it is not persisted. On de-serializing, current value of count is used.


new Counter(); simply increments the variable count by 1.


System.out.println(Counter.getCount()); => Prints 3 on to the console.

Discussion

Think the marked answer is wrong, or have a better explanation? Share it below — comments appear after review.

You must be logged in to post a comment.

Preparing For

Your Certification?

255+ certifications
Detailed explanations
Free PDF samples

Has All The Questions You Need