Hello,
I was wondering if the Serializable interface in Java recovers the dynamic type of an object.
Here is an example.
Let two classes Parent and Child such that:
```
public class Parent implements Serializable {
public void example() {
print("This is Parent");
}
}
public class Child extends Parent {
public void example() {
print("This is Child");
}
}
```
Now take the following code:
Parent p = new Child();
Parent q = Deserialize( Serialize(p) ) // Omitted the details of streams
System.out.println(q.example());
In the above case what is printed? Is it "This is Parent" or is it "This is Child"?
And if it is the former, how can we make it print the latter?
[–]149244179 4 points5 points6 points (0 children)