请阅读下面程序 publicclassExampleStringBuffer{ publicstaticvoidmain(String[]args){ StringBuffersb=newStringBuffer(“test”): System.Out.p

admin2013-12-02  11

问题 请阅读下面程序
publicclassExampleStringBuffer{
publicstaticvoidmain(String[]args){
StringBuffersb=newStringBuffer(“test”):
System.Out.println(“buffer=”+sb);
System.out.println(“length=”+sb.1ength
());})
程序运行结果中在”length=”后输H1的值是(    )。

选项 A、10
B、4
C、20
D、30

答案B

解析 本题对StringBuffer(Stringstr)构造方法,用str给出字符串的初始值。并分配16个字符的缓存。因此,字符串sb的初始值是“test”,并且包含16个字符的缓存。length()方法用来获得字符串长度,不包含缓存。故程序运行结果中在“length=”后输出的值应该是字符串sb的长度。即4。
转载请注明原文地址:https://kaotiyun.com/show/OLID777K
0

最新回复(0)