Marcus Kelvin wrote:So I have some study material with sample code which includes this:
The point of the example was just to demonstrate some things about interfaces, inheritance, and assignment -- beyond this point "ser" is not used. But I know what serialization is and was curious about the interface. Eventually I got it to work (altho I didn't check the binary output...). Does this mean Array implements Serializable?
Yes,
Java arrays implement Serializable. Note, though, that they are not of class "Array".
I'm not sure because: I then tried assigning a object instance from a class which does not implement Serializable. This compiled fine:
Right, because the check for implementing Serializable happens at runtime.
At runtime, the code in the catch block doesn't happen.
Yes it does, if inappropriateObj does not implement Serializable.
Also, note that you never need to call toString() inside a println() method, or when concatenating with another
String.
Also, note that it would be better to call whoops.printStackTrace() to get more details about what went wrong and where. Not a big deal here, but in more complex code, it will help a lot.