• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

doubt regarding serialization in java

 
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
guys,

if we have a class like :

class foo implements Serializable{

-------
-------
}

and then we do -

class fofo extends foo{

------------
------------
}

then is class fofo also Serialized?
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, a fofo object is a foo object, which means that it implements serializable.

Henry
 
Bartender
Posts: 6663
5
MyEclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This applies to all interfaces as well. Once you provide an implementation, all subclasses inherit that implementation.
 
author and cow tipper
Posts: 5009
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Indeed, if a parent class implements Serializable, the subclass is-a serializable object. But remember, Serializable is as much a commitment as it is an implementable interface. Simply saying a class is Serializable isn't enough...you must live up to the associated commitment.

Here's a snippet from the sun tutorial:

Sun Tutorial on Serialization: java.sun.com/docs/books/tutorial/javabeans/persistence/index.html


The Serializable interface provides automatic serialization by using the Java Object Serialization tools. Serializable declares no methods; it acts as a marker, telling the Object Serialization tools that your bean class is serializable. Marking your class Serializable means you are telling the Java Virtual Machine (JVM) that you have made sure your class will work with default serialization. Here are some important points about working with the Serializable interface:

* Classes that implement Serializable must have a no-argument constructor. This constructor will be called when an object is "reconstituted" from a .ser file.
* You don't need to implement Serializable in your class if it is already implemented in a superclass.
* All fields except static and transient fields are serialized. Use the transient modifier to specify fields you do not want serialized, and to specify classes that are not serializable.



-Cameron McKenzie
[ January 01, 2007: Message edited by: Cameron W. McKenzie ]
 
sachin yadav
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you so much all of you for your reply
 
reply
    Bookmark Topic Watch Topic
  • New Topic