public final void writeObject(Object obj)
throws IOException
Write the specified object to the ObjectOutputStream. The class of the object, the signature of the class, and the values of the non-transient and non-static fields of the class and all of its supertypes are written. Default serialization for a class can be overridden using the writeObject and the readObject methods. Objects referenced by this object are written transitively so that a complete equivalent graph of objects can be reconstructed by an ObjectInputStream.
Exceptions are thrown for problems with the OutputStream and for classes that should not be serialized. All exceptions are fatal to the OutputStream, which is left in an indeterminate state, and it is up to the caller to ignore or recover the stream state.
So, the default serializaion is used. If the object was not serialized, then NotSerializableException is thrown.
Imposing the restriction at compile time wouldn't actually help much, as it would only detect the case where the root object wasn't serializable. I suspect it would also make ObjectOutputStream.writeObject() impossible to write, as it calls itself recursively to write the non-transient instance data of the object, and it only sees those as Objects, not as Serializables.