← Back to libraryQuestion 40 of 273
JavaIntermediate

Transient Keyword in Serialization

📖 Detailed Explanation:

The `transient` keyword marks fields that should NOT be saved during serialization. When an object is deserialized, transient fields are initialized to default values (null for objects, 0 for numbers). Use transient for: sensitive data (passwords, API keys), derived fields (calculated values), or non-serializable objects.

🧩 Use Case:

public class User implements Serializable { public String name; transient public String password; // Never saved } When deserialized, password will be null.

🎯 Scenario-Based Interview Question:

If you have a 'final transient' variable, will it be serialized?