How serialization works when only subclass implements serializable

后端 未结 3 1981
悲哀的现实
悲哀的现实 2020-12-14 01:48

Only subclass has implemented Serializable interface.

import java.io.*;

public class NewClass1{

    private int i;
    NewCla         


        
3条回答
  •  情深已故
    2020-12-14 02:25

    I've not tested it, but you shall get a NotSerializableException if serializing the instance of base class. It is the same when your class contains some members that are not Serializable.

    Means if you create an object NewClass1 nc1 = new NewClass1(); and try to serialize the obj nc1, you will get the exception that you want.

提交回复
热议问题