单项选择题

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();


您可能感兴趣的试卷

你可能感兴趣的试题

2.单项选择题When comparing java.io.BufferedWriter to java.io.FileWriter, which capability exists as a method in only one of the two?() 

A. closing the stream
B. flushing the stream
C. writing to the stream
D. marking a location in the stream
E. writing a line separator to the stream

3.多项选择题

10. class MakeFile { 
11. public static void main(String[] args) { 
12. try { 
13. File directory = new File(”d”); 
14. File file = new File(directory,”f”); 
15. if(!file.exists()) { 
16. file.createNewFile(); 
17. } 
18. } catch (IOException e) { 
19. e.printStackTrace 
20. } 
21. } 
22. } 
The current directory does NOT contain a directory named “d.” Which three are true?()

A. Line 16 is never executed.
B. An exception is thrown at runtime.
C. Line 13 creates a File object named “d”.
D. Line 14 creates a File object named “f‟.
E. Line 13 creates a directory named “d” in the file system.
F. Line 16 creates a directory named “d” and a file  “f”  within it in the file system.
G. Line 14 creates a file named "f " inside of the directory named “d” in the file system.

6.多项选择题

public class TestString3 { 
public static void main(String[] args) { 
// insert code here 
System.out.println(s); 
} 
} 
Which two code fragments, inserted independently at line 3, generate the output 4247?()

A. String s = “123456789”; s = (s-”123”).replace(1,3,”24”) - “89”;
B. StringBuffer s = new StringBuffer(”123456789”); s.delete(0,3).replace( 1,3, “24”).delete(4,6);
C. StringBuffer s = new StringBuffer(”123456789”); s.substring(3,6).delete( 1 ,3).insert(1, “24”);
D. StringBuilder s = new StringBuilder(”123456789”); s.substring(3,6).delete( 1 ,2).insert( 1, “24”);
E. StringBuilder s = new StringBuilder(”123456789”); s.delete(0,3).delete( 1 ,3).delete(2,5).insert( 1, “24”);

8.单项选择题

public class MyLogger { 
private StringBuilder logger = new StringBuuilder(); 
public void log(String message, String user) { 
logger.append(message); 
logger.append(user); 
} 
} 
The programmer must guarantee that a single MyLogger object works properly for a multi-threaded system. How must this code be changed to be thread-safe?() 

A. synchronize the log method
B. replace StringBuilder with StringBuffer
C. No change is necessary, the current MyLogger code is already thread-safe.
D. replace StringBuilder with just a String object and use the string concatenation (+=) within the log method

9.单项选择题

Given this method in a class: 
public String toString() { 
StringBuffer buffer = new StringBuffer(); 
buffer.append(‟<‟); 
buffer.append(this.name); 
buffer.append(‟>‟); 
return buffer.toString(); 
} 
Which is true?() 

A. This code is NOT thread-safe.
B. The programmer can replace StringBuffer with StringBuilder with no other changes.
C. This code will perform well and converting the code to use StringBuilder will not enhance the performance.
D. This code will perform poorly. For better performance, the code should be rewritten: return “<“+ this.name + “>”;