Which code, inserted at line 14, will allow this class to correctly serialize and deserialize?

Refer to the Exhibit.
Which code, inserted at line 14, will allow this class to correctly serialize and deserialize?

1. import java.io.*;
2. public class Foo implements Serializable {
3. public int x, y;
4. public Foo(int x, int y){
5. this.x = x; this.y = y;
6. }
7.
8. private void writeObject(ObjectOutputStream s)
9. throws IOException{
10. s.writeInt(x); s.writeInt(y);
11. }
12.
13. private void readObject(ObjectInputStream s)
14. throws IOException, ClassNotFoundException {
15. //insert code here
16. }
17. }

Refer to the Exhibit.
Which code, inserted at line 14, will allow this class to correctly serialize and deserialize?

1. import java.io.*;
2. public class Foo implements Serializable {
3. public int x, y;
4. public Foo(int x, int y){
5. this.x = x; this.y = y;
6. }
7.
8. private void writeObject(ObjectOutputStream s)
9. throws IOException{
10. s.writeInt(x); s.writeInt(y);
11. }
12.
13. private void readObject(ObjectInputStream s)
14. throws IOException, ClassNotFoundException {
15. //insert code here
16. }
17. }

A.
s.defaultReadObject();

B.
this = s.defaultReadObject();

C.
y = s.readInt(); x = s.readInt();

D.
x = s.readInt(); y = s.readInt();



Leave a Reply 0

Your email address will not be published. Required fields are marked *