Java程序设计

单选题创建字符串s:Strings=newString(“hello”);以下()语句将改变s。A s.append(“aaa”)B s.concat(s)C s.substring(3)D 以上语句都不会

题目
单选题
创建字符串s:Strings=newString(“hello”);以下()语句将改变s。
A

s.append(“aaa”)

B

s.concat(s)

C

s.substring(3)

D

以上语句都不会

参考答案和解析
正确答案: D
解析: 暂无解析
如果没有搜索结果,请直接 联系老师 获取答案。
相似问题和答案

第1题:

假设有以下代码: String s="hello"; String t="hello"; char c[ ]={'h','e','l','l','o'}; 下列选项中,返回false的语句是______。

A.s.equals(t);

B.t.equals(c);

C.s==t;

D.t.equals(new String("hello"));


正确答案:B
解析: ==操作符所比较的是操作符两端的操作数是否是同一个对象,而String的equals( )方法所比较的是两个String对象的内容是否一样,其参数是一个String对象时才有可能返回true,其他对象都返回false。因此只有选项B符合题意。

第2题:

Strings="hello";Stringt="hello";charc[]={’h’,’e’,’l’,’l’,’o’};Whichreturntrue?()

A.s.equals(t);

B.t.equals(c);

C.s==t;

D.t.equals(newString("hello"));

E.t==c;


参考答案:A, C, D
这个在前面第10题的equals()方法和==操作符的讨论中论述过。==操作符比较的是操作符两端的操作数是否是同一个对象,而String的equals()方法比较的是两个String对象的内容是否一样,其参数是一个String对象时才有可能返回true,其它对象都返回假。需要指出的是由于s和t并非使用new创建的,他们指向内存池中的同一个字符串常量,因此其地址实际上是相同的(这个可以从反编译一个简单的测试程序的结果得到,限于篇幅不列出测试代码和反编译的分析),因此答案c也是正确的。

第3题:

关于以下程序段,正确的说法是() 1.Strings1=”abc” ”def”; 2.Strings2=newString(s1); 3.if(s1==s2) 4.System.out.println(“==succeeded”); 5.if(s1.equals(s2)) 6.System.out.println(“.equals()succeeded”);

A.行4与行6都将执行

B.行4执行,行6不执行

C.行6执行,行4不执行

D.行 4、行6都不执行


参考答案:C

第4题:

下列代码的执行结果是()。publicclasstest5{publicstaticvoidmain(Stringargs[]){Strings1=newString("hello");Strings2=newString("hello");System.out.prim(s1==s2);System.out.print(",");System.out.println(s1.equals(s2));}

A.true,false

B.true,true

C.false,true

D.false,false


正确答案:C

第5题:

publicclassX{publicstaticvoidmain(Stringargs){strings=newstring(Hello”);modify(s);System.out.printIn(s);}publicstaticvoidmodify(Strings){s+=world!”;}}Whatistheresult?()

A.Theprogramrunsandprints“Hello”

B.Anerrorcausescompilationtofail.

C.Theprogramrunsandprints“Helloworld!”

D.Theprogramrunsbutabortswithanexception.


参考答案:A

第6题:

importjava.util.*;publicclassWrappedString{privateStrings;publicWrappedString(Strings){this.s=s;}publicstaticvoidmain(String[]args){HashSeths=newHashSet();WrappedStringws1=newWrappedString(”aardvark”);WrappedStringws2=newWrappedString(”aardvark”);Strings1=newString(”aardvark”);Strings2=newString(”aardvark”);hs.add(ws1);hs.add(ws2);hs.add(s1);hs.add(s2);System.out.println(hs.size());}}Whatistheresult?()

A.0

B.1

C.2

D.3

E.4

F.Compilationfails.

G.Anexceptionisthrownatruntime.


参考答案:D

第7题:

publicclassX{publicstaticvoidmain(String[]args){strings=newstring(Hello”);modify(s);System.out.printIn(s);}publicstaticvoidmodify(Strings){s+=world!”;}}Whatistheresult?()

A.Theprogramrunsandprints“Hello”

B.Anerrorcausescompilationtofail.

C.Theprogramrunsandprints“Helloworld!”

D.Theprogramrunsbutabortswithanexception.


参考答案:A

第8题:

创建字符串s:String s=new String(“abcd”);以下 将改变s。()

A.s.append(“x”);

B.s.concat(“y”);

C.s.substring(3);

D.以上语句都不会


参考答案:D

第9题:

以下选项中正确的语句组是( )。

A)char s[];s="HELLO!";

B)char*s;s={"HELLO!"};

C)char s[10];s="HELLO!";

D)char *s;s="HELLO!";


正确答案:D
本题考查数组和字符串的赋值。选项A)中数组s没有明确其大小就赋值是错误的。选项B)中不能有大括号,选项C)中的写法应该为{'H''E''L''L''O"!'}。

第10题:

下列语句输出结果为( )。 public class test { public static void main (String args[]) { Strings1=newString("HOW"); Strings2=newString("How"); System.out.println(!(s1.equals(s2))): } }

A.假

B.真

C.0

D.1


正确答案:A

更多相关问题