whether a class should be serializable
Hi Gurus
1)//////////////////
class Aimplements Serializable
{
}
class Bextends A
{
}
can you tell me B will be serializable or not.
2////
class A
{
}
class Bextends A,implements Serializable
{
}
class A will be serializable or not?
Thanks in Adnvance
[843 byte] By [
ayaza] at [2007-10-3 5:03:35]

What? That's complete rubbish.
Since Serializable is an interface, all sub-classes of classes which implement Serializable are also Serializable. (This is just normal inheritance stuff).
There is one caveat: If a superclass does not implement Serializable (directly or indirectly), and a subclass does. then the superclass must have a no-args constructor. What the original reply said is completely reversed.
Note that in general, constructors are not used during the de-serialization of objects (because we're not constructing these objects, we're just de-serializaing pre-existing objects) except in the case mentioned above.
OP: You could have tested this in the time it took you to post to this forum
danny is correct...lets see how...
In the first case since the superclass implements Serializable the sub class doesnot need to explicitly implement Serializable as it would inherit it anyway...the implementation that is. So the subclass would be serializable.
In the second case the superclass is not Serializable since it does not explicitly say that it implements Serializable and the class Object is itself not serializable. In this case the subclass would not be serilizable unless the superclass has a default constructor. What would happen is when the subclass is deserialized the inherited part of the subclass could not be properly recreated unless there is a default constructor.
hope this helps...
If the super class A implements Serializable as per the concept of "Inheritance" all the methods implemented by class A would hold good for the class B also.
So by default class B would also implement the properites of Serialization and i feel that constructors have nothing to do in this case as they are basically used only for initializing the class members.
Regards..