hi, I wrote this code and it is compiling and running. Without java.io.NotSerializableException: error . I was expecting error as my Cat object created at line 4 is not serialized but when i replace line 4 with Animal a=new Animal() which is superclass of Cat i am getting error Why is it so? I am not getting any error when i am serializing Cat object but when i try to serialize Animal object i am getting exception. Any suggestion.?
The question is not so clear. you didnt included the Car and Animal class definitions in the code. In general, any class that wants to be serialized has to implement the Serializable Interface(The class itself or any one of its super classes). Otherwise this exception is thrown.