In java, if a class implements Serializable but is abstract, should it have a serialVersionUID long declared, or do the subclasses only require that?
In this case it is indeed the intention that all the sub classes deal with serialization as the purpose of the type is to be used in RMI calls.
The serialVersionUID is provided to determine compatibility between a deseralized object and the current version of the class.
As such, it isn’t really necessary in the first version of a class, or in this case, in an abstract base class. You’ll never have an instance of that abstract class to serialize/deserialize, so it doesn’t need a serialVersionUID.(Of course, it does generate a compiler warning, which you want to get rid of, right?)
It turns out james’ comment is correct. The serialVersionUID of an abstract base class does get propagated to subclasses. In light of that, you do need the serialVersionUID in your base class.
The code to test:
Run the main in Sub once to get it to create and save an object. Then change the serialVersionUID in the Base class, comment out the lines in main that save the object (so it doesn’t save it again, you just want to load the old one), and run it again. This will result in an exception