Leandro Coutinho wrote:
What do you think is the output?
The code compiles fine, but gives InvalidClassException on running.
It runs without exception if the code which reads the serialized file is commented.
It would compile fine but would return a InvalidClassException when run.
When Dog(serializable sublass) is deserialised it would call the default constructor of its superclass because the superclass(Animal) isn't a Serializable Object.
Since the Animal class doesnt have a default constructor it would raise a flag and throw a suitable exception.
If you modify your code to look like this
then the code would not throw the exception when deserializing.
Remember that although it is nice to know about, serialization is no longer on the current exam.
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
Accept for @Override, @SupressWarnings and @Deprecated, annotations aren't used often in Java SE. They're used very often in Java EE but the Java EE exams cover those topics in detail.
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.