niusouti.com

publicclassX{publicstaticvoidmain(Stringargs){strings=newstring(Hello”);modify(s);System.out.printIn(s);}publicstaticvoidmodify(Strings){s+=world!”;}}Whatistheresult?()A.Theprogramrunsandprints“Hello”B.Anerrorcausescompilationtofail.C.Theprogramrunsandpri

题目
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
更多“publicclassX{publicstaticvoidmain(Stringargs){strings=newstring(Hello”);modify(s);System.out.printIn(s);}publicstaticvoidmodify(Strings){s+=world!”;}}Whatistheresult?() ”相关问题
  • 第1题:

    下列代码的执行结果是()。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

  • 第2题:

    下列代码段的执行结果是( )。 public class Test { public static void main(String args[]) } String s1=new String("hello"); String s2=new String{"hello"); System.out.println(s1==s2); System.out.println(s1.equal(s2)); } }

    A.true false

    B.true true

    C.false true

    D.false false


    正确答案:C
    解析:本题考查比较运算符(==)的使用。比较运算符不仅可以用于基本数据类型的数据之间的比较,还可以用于复合数据类型的数据之间的比较。题中s1和s2的值虽然都是hello,但是由于它们是不同的对象,因此运算后的结果为false。如果需要比较两个对象的值是否相同,则可以调用equals()方法。所以程序最后输出false和true。

  • 第3题:

    写出以下程序的运行结果? public class Test{ public static void main(String argv[]){ String s = new String("hello"); myMethod(s); System.out.print("s=" + s); } public static void myMethod(String s){ s = s + "!"; } }

    A.s=hello!

    B.s=hello

    C.hello!

    D.hello


    2,2,3

  • 第4题:

    下列代码段的执行结果是( )。 public class Test { public static void main(String args[ ]) { String s1= new String("hello"); String s2= new String("hello"); System.out.println(s1==s2); System.out.println(s1.equal(s2)); } }

    A.true false

    B.true true

    C.false true

    D.false false


    正确答案:C
    解析:本题考查比较运算符(==)的使用。比较运算符不仅可以用于基本数据类型的数据之间的比较,还可以用于复合数据类型的数据之间的比较。题中s1和s2的值虽然都是hello,但是由于它们是不同的对象,因此运算后的结果为false。如果需要比较两个对象的值是否相同,则可以调用equals()方法。所以程序最后输出false和true。

  • 第5题:

    1、写出以下程序的运行结果? public class Test{ public static void main(String argv[]){ String s = new String("hello"); myMethod(s); System.out.print("s=" + s); } public static void myMethod(String s){ s = s + "!"; } }

    A.s=hello!

    B.s=hello

    C.hello!

    D.hello


    编译错误