Meaningless Drivel is fun!*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Does private instance variable participate Serialization process? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Does private instance variable participate Serialization process?" Watch "Does private instance variable participate Serialization process?" New topic
Author

Does private instance variable participate Serialization process?

V. Potluri
Ranch Hand

Joined: Mar 29, 2007
Posts: 36
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

Joined: Oct 09, 2007
Posts: 206

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.


Enjoy, Chander
SCJP 5, Oracle Certified PL/SQL Developer
Pranav Bhatt
Ranch Hand

Joined: Mar 20, 2006
Posts: 284
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

Joined: Mar 29, 2007
Posts: 36
Hi chander and Pranav,

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

Regards,
Gopal
 
Don't get me started about those stupid light bulbs.
 
subject: Does private instance variable participate Serialization process?
 
Similar Threads
transient variable ? is there any other way
interview question of the day (08/04/2008)
Any one can explain this?
Object Serialization Process?
instance variables