单项选择题

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 + “>”;


您可能感兴趣的试卷

你可能感兴趣的试题

3.单项选择题

1. public class Boxer1 { 
2. Integer i; 
3. int x; 
4. public Boxer1(int y) { 
5. x=i+y; 
6. System.out.println(x); 
7. } 
8. public static void main(String[] args) { 
9. new Boxer1(new Integer(4)); 
10. } 
11. } 
What is the result?() 

A. The value “4” is printed at the command line.
B. Compilation fails because of an error in line 5.
C. Compilation fails because of an error in line 9.
D. A NullPointerException occurs at runtime.
E. A NumberFormatException occurs at runtime.
F. An IllegalStateException occurs at runtime.

7.单项选择题

11. public void someMethod(Object value) { 
12. // check for null value .... 
20. System.out.println(value.getClass()); 
21. } 
What, inserted at line 12, is the appropriate way to handle a null value?() 

A. assert value == null;
B. assert value !null, “value is null”;
C. if (value == null) { throw new AssertionException(”value is null”);
D. if (value == null) { throw new IllegalArgumentException(”value is null”);