Java object Serialization and inheritance
问题 Say you have these two classes, Foo and Bar where Bar extends Foo and implements Serializable class Foo { public String name; public Foo() { this.name = "Default"; } public Foo(String name) { this.name = name; } } class Bar extends Foo implements java.io.Serializable { public int id; public Bar(String name, int id) { super(name); this.id = id; } } Notice that Foo doesn't implement Serializable . So what happens when bar is serialized? public static void main(String[] args) throws Exception {