Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
The moose likes Java in General and the fly likes doubt regarding serialization in java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "doubt regarding serialization in java " Watch "doubt regarding serialization in java " New topic

doubt regarding serialization in java

sachin yadav
Ranch Hand

Joined: Nov 24, 2005
Posts: 156

if we have a class like :

class foo implements Serializable{


and then we do -

class fofo extends foo{


then is class fofo also Serialized?
Henry Wong

Joined: Sep 28, 2004
Posts: 20517

Yes, a fofo object is a foo object, which means that it implements serializable.


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Deepak Bala

Joined: Feb 24, 2006
Posts: 6662

This applies to all interfaces as well. Once you provide an implementation, all subclasses inherit that implementation.

SCJP 6 articles - SCJP 5/6 mock exams - More SCJP Mocks
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4968

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 must live up to the associated commitment.

Here's a snippet from the sun tutorial:

Sun Tutorial on Serialization:

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

Joined: Nov 24, 2005
Posts: 156
Thank you so much all of you for your reply
I agree. Here's the link:
subject: doubt regarding serialization in java
It's not a secret anymore!