Serialization and Deserialization in Java | Code Factory

Reference Link : Link

Donate : Link

Java Serialization allows us to convert Java Object to a Stream of bytes which we can send through a network or save in a file or even in a DB for future usage. Deserialization is the process of converting a stream of bytes back to Java Object which can be used in our program. We will be implementing interface to achieve serialization

The serializable interface in java is a marker interface (method with no body).

Output :

Is sub class Serializable?

If the parent class is Serializable then all the sub class will be Serializable as well.

Output :

Other Class Reference in a Serializable class

If we have a non-serializable reference of a class inside a Serializable class, then serialization operation will not be performed.In such case, NonSerializableException will be thrown.

I have changed code of and classes

Output :