Multiple choice java

How can you prevent a member variable from becoming serialized?

  1. By marking it private

  2. By marking it volatile

  3. By marking it transient

  4. You can not.

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

The transient keyword in Java explicitly prevents a field from being serialized. When an object is serialized, transient fields are skipped and get default values upon deserialization.