publicclassX{publicstaticvoidmain(String[]args){Strings1=newString(true”);Booleanb1=newBoolean(true);if(s2.equals(b1)){System.out.printIn(Equal”);}}}Whatistheresult?()A.Theprogramrunsandprintsnothing.B.Theprogramrunsandprints“Equal”C.Anerroratline5causesc

题目
publicclassX{publicstaticvoidmain(String[]args){Strings1=newString(true”);Booleanb1=newBoolean(true);if(s2.equals(b1)){System.out.printIn(Equal”);}}}Whatistheresult?()

A.Theprogramrunsandprintsnothing.

B.Theprogramrunsandprints“Equal”

C.Anerroratline5causescompilationtofail.

D.Theprogramrunsbutabortswithanexception.


相似考题
更多“publicclassX{publicstaticvoidmain(String[]args){Strings1=newString(true”);Booleanb1=newBoolean(true);if(s2.equals(b1)){System.out.printIn(Equal”);}}}Whatistheresult?() ”相关问题
  • 第1题:

    publicclassX{publicstaticvoidmain(Stringargs){Strings1=newString(true”);Booleanb1=newBoolean(true);if(s2.equals(b1)){System.out.printIn(Equal”);}}}Whatistheresult?()

    A.Theprogramrunsandprintsnothing.

    B.Theprogramrunsandprints“Equal”

    C.Anerroratline5causescompilationtofail.

    D.Theprogramrunsbutabortswithanexception.


    参考答案:A

  • 第2题:

    下列程序的执行结果是______。 public class Test9 { public static void main(String[] args) { String s1 = new String("I am a girl"); String s2 = new String("I am a girl"); System.out.println (s1.equal (s2)); } }

    A.true

    B.假

    C.I amgirl

    D.都不正确


    正确答案:A
    解析:如果需要比较两个对象的值是否相同,则可以调用equal()方法,如果被比较的两个对象相等,则返回true,否则返回false。

  • 第3题:

    执行下列程序段之后,变量b的值为______。 public class Test9 { public static void main(String[] args) { int i=12; int j=24; boolean b1=true; boolean b=(j%i== 0)&&(!b1) ||(j/i!=2); System.out.println(b); } }

    A.true

    B.假

    C.1

    D.0


    正确答案:B
    解析:表达式执行次序为:首先做!b1得到false:然后做j%i==0得到true;再做j/i!=2得到false:然后做&&得到false;最后是||得到false。

  • 第4题:

    执行下列程序段之后,变量b的值为( )。 public class Test { public static void main (String[] args) { int i = 12; int j = 24; boolean b1 = true; booleanb=(j%i==0)&&(! b1) || (j/i! =2); System. out. println (B); } }

    A.true

    B.false

    C.0

    D.1


    正确答案:B
    解析:表达式执行次序为:首先做!b1得到false;然后做j%i==0得到true;再做j/i!=2得到false;然后做&&得到false;最后是||,得到false。

  • 第5题:

    当执行下面代码时,会输出( )。 Boolean b1 = new Boolean(true); Boolean b2 = new Boolean(true); if (b1 == b2) if (bi.equals(b2)) System. out.printin ("a"); else System. out. println ("b"); else if (bi.equals(b2)) System. out.println ("c"); else System. out.printIn("d");

    A.a

    B.b

    C.c

    D.d


    正确答案:C
    解析:本题考查对简单类型中的boolean类型的类封装的理解和掌握。对应于基本数据类型boolean的类封装是Boolean。它的构造函数的原型是Boalean(boolean value),将boolean值的数据转换为Boolean的对象。成员函数 equals()的原型是Boolean equals(Object Obj),当且仅当obj对象为Boolean对象且它的布尔值与该对象的布尔值相同时返回true。注意关系运算符==用来比较两个操作数的值是否相等。它一般只能用在基本数据类型间的比较,对于复杂的数据类型,这种比较往往都是没有意义的,对于这种没有意义的比较,其结果都为false。在本题的代码中,先创建两个Boolean类的对象b1和b2,并且它们的布尔值都为 true。然后直接对这两个对象进行==关系运算,这样的运算结果肯定为false,程序流程就走到第1层的else语句那里了,然后再用equals函数对两个对象的布尔值进行比较。因为它们的布尔值都为true,所以返回结果为true。这样输出的结果就为C。