What happens if a superclass is not serializable but its subclass is, and we serialize an object of the subclass?

  • Only the subclass fields will be serialized.
  • Serialization will fail.
  • Serialization will proceed without errors.
  • The superclass fields will be serialized, but not the subclass fields.
If a superclass is not serializable but its subclass is, attempting to serialize an object of the subclass will result in a java.io.NotSerializableException. This happens because the superclass needs to be serializable for the serialization process to work correctly. The other options are incorrect, as they imply successful serialization without issues.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *