1

If Base class doesn't implement Serializable Interface but Derived class implements Serializable interface, will I be able to deserialiaze the serialized object? Because when I tried to do it, I got ClassNotFoundException.

Prasad S
  • 35
  • 7

2 Answers2

0

ClassNotFound means that the required .class file does not exist in the context of the JVM where you try to de-serialize (so that is a classpath setup problem!)

And then: this will only work if all superclasses that are not Serializiable contain a no-argument default constructor (see here for further information).

Community
  • 1
  • 1
GhostCat
  • 137,827
  • 25
  • 176
  • 248
  • You are welcome. And just to be sure you don't miss that - you can accept one (and after reaching upvote level) also upvote one or more of the answers ;-) – GhostCat Apr 11 '17 at 19:41
0

Yes, You won't be able to deserialize because your member variable is of reference type and if it does not implement serializable then the value for the reference variable will be null in the stream after serialization. So, while deserializing , Java internally call Class.forname() to get that reference variable back into object. Since it was null , you will get ClassNotFoundException .

Soltn.. :- Make the reference variable class to implement serializable

F0rG0tTeN
  • 96
  • 7