why to use transient variables when static variables can be
used for Serialization
Answer Posted / ram
Both static & Transient are may not be serialized.
Static means one per class not one per object. Static
variables are not saved and when an object is deserialized,
it will have whatever static variable its class currently
has. Don’t make serializable objects dependent on a
dynamically-changing static variable. It might not be the
same when the object comes back.
Transient variables are given a value of NULL for object
references and defaults (0, false, etc) for primitives.
| Is This Answer Correct ? | 12 Yes | 4 No |
Post New Answer View All Answers
What are accessor methods in java?
How do I stop concurrentmodificationexception?
What is a void method java?
What is the benefit of abstract class?
Can static methods be inherited?
What is the protected method modifier?
Can we create an object if a class doesn't have any constructor ( not even the default provided by constructor ) ?
What are memory tables?
How do you avoid global variables?
What is a platform?
What is protected access modifier?
Which list is sorted in java?
What is the difference between the font and fontmetrics classes in java programming?
What is use of valueof () in java?
What are the different types of constructor?