How can a developer prevent a field from being serialized?
- Mark the field as final.
- Mark the field as private.
- Mark the field as static.
- Mark the field as transient.
In Java, to prevent a field from being serialized, you can mark it as transient. When a field is marked as transient, it will not be included in the serialization process. The other options do not directly prevent serialization. Marking a field as final has no impact on serialization. Marking it as static means the field will be serialized. Marking it as private affects only access, not serialization.
Loading...
Related Quiz
- What is the primary purpose of using synchronized methods in Java?
- What is the default value of a local variable of data type boolean in Java?
- Which searching algorithm would work even if the data is not sorted?
- If a method in an interface is declared without an access modifier, it is implicitly ________.
- Which method can be used to temporarily pause the execution of a thread for a specified time?