Share:- Whatsapp Facebook Facebook

------------------------------------- Welcome to Developerhelpway Q&A, where you can ask questions and receive answers from other members of the community.


0 votes
If super class implement Serializable interface, then child class get autometically serialized. How can you avoid new class or child class to being serialized?
in Java by

1 Answer

0 votes

This is one of the tricky interview question in java Serialization. As we know that the Super Class of a Class already implements Serializable interface then its already Serializable, since you can not unimplemented an interface its not really possible to make it Non Serializable class.

But, yes there is a way to avoid serialization of new class.

To avoid serialization you need to implement "Externalizable" interface. Externalizable interface contains writeObject() and readObject() methods. In our Class must be implemented the Externalizable interface and override writeObject() and readObject() methods and need to throw SerializationNotSupportException from those method.

by (2.8k points)