首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2SE开发 >

谁来帮小弟我讲解一下这道题~多谢

2011-11-28 
谁来帮我讲解一下这道题~~~谢谢Java code1. import java.io.*2. public class Foo implements Serializab

谁来帮我讲解一下这道题~~~谢谢

Java code
1. import java.io.*;2. public class Foo implements Serializable {3. public int x, y;4. public Foo( int x, int y) { this.x = x; this.y = y; }5.6. private void writeObject( ObjectOutputStream s)7. throws IOException {8. s.writeInt(x); s.writeInt(y)9. }10.11. private void readObject( ObjectInputStream s)12. throws IOException, ClassNotFoundException {13.14. // insert code here15.16. }17. }Which code, inserted at line 14, will allow this class to correctlyserialize and deserialize?A. s.defaultReadObject();B. this = s.defaultReadObject();C. y = s.readInt(); x = s.readInt();D. x = s.readInt(); y = s.readInt();Answer: D

谁来给我讲讲这道题什么意思,看不太懂。
  顺便说一下C选项为什么不对~~谢谢~~

[解决办法]
有先后顺序啊
[解决办法]
在序列化的时候,writeObject与readObject之间是有先后顺序。readObject将最先write的object read出来。
可以理解为先进先出
[解决办法]
s.writeInt(x); s.writeInt(y)

 写进先X后Y, 读也是一个顺序

[解决办法]
这段代码先通过writeInt()方法些入x,y,读的时候顺序也要求是一样的.

热点排行