1.在Java中,以下方法属于String类的有( )
(选择两项)
A: insert (int offset,)
B: replace(int start, int end,)
C: split (String regex) ;
D: endsWith(String suffix) ;
B: replace(int start, int end,)
C: split (String regex) ;
D: endsWith(String suffix) ;
此题选择
CD:
A :insert是将 char 参数的字符串表示形式插入此序列中
B: replace 使用给定 String 中的字符替换此序列的子字符串中的字符
A和B都是StringBuilder类里面的方法
C :split 根据给定正则表达式的匹配拆分此字符串
D :endsWith 测试此字符串是否以指定的后缀结束
C,D是属于String类的方法
2.
在Java中,送行如下代码段,则输出結果为( )。
public class Test
public static String str = "welcome";
public static void main(String[] args) {
Test test = new Test() ;
test. chang() ;
System. out. print(str) ;
}
public void chang() {
str = welcome bdqn!" ;
}
}
A: welcome
B: 编译错误
C: welcome bdqn
D: 编译通过,运行时报错!
此题选C: str为静态变量,同类下的方法内可直接调用,在change方法,给str赋值为“welcome bdqn!”,所以答案选C