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 here 15. 16. } 17. } Which code, inserted at line 14, will allow this class to correctly serialize and deserialize?()
A、 s.defaultReadObject();
B、 this = s.defaultReadObject();
C、 y = s.readInt(); x = s.readInt();
D、 x = s.readInt(); y = s.readInt();
相关问题推荐
-
TCP/IP在多个层次引入了安全机制,其中TLS协议位于(44)。
A.数据链路层
B.网络层
C.传输层
D.应用层
-
int index = 1; String test = new String; String foo = test[index]; What is the result?()
A、 Foo has the value “”
B、 Foo has the value null
C、 An exception is thrown
D、 The code will not compile
-
Which two are true?()
AAn encapsulated, public class promotes re-use.
BClasses that share the same interface are always tightly encapsulated.
CAn encapsulated class allows subclasses to overload methods, but does NOT allow overriding methods.
DAn encapsulated class allows a programmer to change an implementation without affecting outside code.
-
public class Test { public static void main(String[] args) { String str = NULL; System.out.println(str); } } What is the result?()
A、 NULL
B、 Compilation fails.
C、 The code runs with no output.
D、 An exception is thrown at runtime.
-
public class X { public static void main(String [] args) { try { badMethod(); System.out.print(“A”); } catch (Exception ex) { System.out.print(“C”); } finally { System.out.print(“B”); } System.out.print(“D”); } public static void badMethod() { throw new Error(); } } What is the result?()
A、 ABCD
B、 Compilation fails.
C、 C is printed before exiting with an error message.
D、 BC is printed before exiting with an error message.
E、 BCD is printed before exiting with an error message.