问题
单项选择题
阅读下面程序 public class ConcatTest{ public static void main(String[] args) { String strl = "abc"; String str2 = "ABC"; String str3 = str1.concat(str2); System.out.println(str3);} } 程序的运行结果是:
A.abe
B.ABC
C.abcABC
D.ABCabc
答案
参考答案:C
解析: 本题考查字符串的使用。String类提供concat(str)方法,该方法将当前字符串对象与指定str字符串相连。题目程序中生成两个字符串变量str1和str2,并为其赋值,然后生成一个字符串变量str3,该字符串变量的值为表达式str1.concat(str2)的结果。表达式str1.concat(str3)是把字符串str1与字符串str2相连,结果为“abcABC”。 因此,程序的运行结果是“abcABC”。本题的正确答案是选项C。