• Post Reply Bookmark Topic Watch Topic
  • New Topic

Serialization: The Return  RSS feed

 
Jose Campana
Ranch Hand
Posts: 339
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good Evening/Night or even morning for some of ya!
I have not been here regularly lately... didn't have many Questions to ask. I hope that's a good sign, but... you know, the bad news is that I have another question *actually,
Here it goes:

What happens when I serialize an Object (that can be serialized) and during serialization that Object calls a method that instantiates Object(s) from another class that are also serializable?

Let me provide some code for further explanation:



The Question here is this:

Will the Object of type/class Cow created at the line with the comment //Here be serialized when main finishes?

Thanks for the support!
Your friend
Jose
 
Deepak Chopra
Ranch Hand
Posts: 433
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

As per my understanding..In your code cow and goat are local variable, as they are defined inside main..so they will not serialize.

However if you have defined cow and goat outside the main method, I mean as a instance variable...then they will be Serialized.

I hope this will clear your doubt.
 
Jose Campana
Ranch Hand
Posts: 339
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Sunny !

Is there anyone else who may want to comment on my thread? feel free to do so.

Best regards!
Jose
 
Milton Ochoa
Ranch Hand
Posts: 336
Firefox Browser Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I dont see te point of the question.

why you ask if the the Cow create inside of the main method will be serializable too?

maybe you dont know this: when you want to serializar a object, you save the state of that object, i mean, the instance variables like say Sunny.

One another thing, when you are serializable a object and that object have reference variables, this references variables needs implement Serializable if you want saves their state too.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!