Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Does private instance variable participate Serialization process?

 
V. Potluri
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have few doubts related to object serialization. Those are as follows:



a] Does instance variable with private access modifier takes part of
object serialization?

b] Does static variable participate in object serialization process?

c] Does instance variable with final modifier participate in object
serialization process?


Thanks in advance,

Regards,
Gopal
 
chander shivdasani
Ranch Hand
Posts: 206
Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
b] NO, static variable does not participate in serialization process. Serialization is strictly restiricted to object and Static variables belong to class. So, Static variables are not serialized.

For other two options, i feel the answer is yes. All the instance variables are serialized except for those who are defined as transient.
 
Pranav Bhatt
Ranch Hand
Posts: 284
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I made edition on my previous answers as i mismatched the and [c] choice, sorry for that, now its fine

a] Does instance variable with private access modifier takes part of
object serialization? [b]Yes


b] Does static variable participate in object serialization process? They simply can't as serialization is associated with objects, static implies class variables.

c] Does instance variable with final modifier participate in object
serialization process? Yes

The below code will give you clear picture-:


This will give you output as-:
before: Fido 56 German Shepherd
before: Sham 56 Australian Shepherd
before: Gathj 56 Beagle
after: Fido 56 German Shepherd
after: Sham 56 Australian Shepherd
after: Gathj 56 Beagle


Here you can see that for static variables serialization has no meaning. As they are class variables.
[ September 17, 2008: Message edited by: Pranav Bhatt ]
 
V. Potluri
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi chander and Pranav,

Thanks for spending your precious time to clear my doubt.
Have a pleasant day ahead!

Regards,
Gopal
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic