Which of the following is a characteristic of the ‘transient’ keyword in Java?

Java MCQ: Which of the following is a characteristic of the ‘transient’ keyword in Java?

a) It prevents serialization of the variable
b) It ensures that the variable is serialized
c) It allows the variable to be accessed from any thread
d) It makes the variable immutable

Answer:

a) It prevents serialization of the variable

Explanation:

The transient keyword in Java is used to indicate that a variable should not be serialized when an object is converted into a byte stream. During the serialization process, all fields of an object are typically saved, but any field marked as transient will be ignored and not included in the serialized representation.

This is useful when certain parts of an object’s state, such as sensitive information or data that can be reconstructed, should not be persisted or transmitted.

Understanding the use of the transient keyword is important for managing the serialization process effectively, especially in scenarios where security or data integrity is a concern.

Reference links:

https://www.rameshfadatare.com/learn-java-programming/
https://www.javaguides.net/p/java-tutorial-learn-java-programming.html

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top