第七章单元测试
测试如下代码:
public class Ref{
public static void main(String[] args) {
StringBuffer sbl = new StringBuffer("Hello");
StringBuffer sb2 = new StringBuffer("Hello");
boolean result = sbl.equals(sb2);
System.out.println(result);
}
}
下述哪条语句正确描述了程序编译和运行的行为?
String alphabet="ABCDEFGHIJKLMNOPQ"
调用alphabet.substring(6,10)返回什么子字符串?
以下程序的调试结果为?
1. public class EqualsTest{
2. public static void main(String args[]){
3. Long LA = new Long(7);
4. Long LB = new Long(7);
5. if(LA==LB) System.out.println("Equal");
6. else System.out.println("Not Equal");
7. }
8. }有如下代码:
public class Test{
public static void main(String args[]) {
String str = new String("World");
char ch[] = {'H','e','l','l','o'};
change(str,ch);
System.out.println(str + "and" + ch);
}
public static void change(String str, char ch[]) {
str = "Changed";
ch[0] = 'C';
}
}
运行后输出的结果是:已知代码: String s = "story";下列语句中合法的是:
A:编译成功,输出为 1 B:编译成功,输出为 0 C:编译成功,输出为 true D:编译成功,输出为 false
答案:编译成功,输出为 false
A:CDEF B: GHIJ C:FGHI D:EFGH
A:编译错误 B: 程序在执行到第5行时出现异常 C:输出"Equal" D:输出"Not Equal"
A:Changed and Cello B:World and Cello C:World and Hello D:World and CelloChanged and Hello
A:String t = s.toLowerCase(); B:s += "books"; C:int len = s.length; D:char c = s[1];