单选题int index = 1;  boolean[] test = new Boolean[3];  boolean foo= test [index];   What is the result?()AFoo has the value of 0.BFoo has the value of null.CFoo has the value of true.DFoo has the value of false.EAn exception is thrown.FThe code will not com

题目
单选题
int index = 1;  boolean[] test = new Boolean[3];  boolean foo= test [index];   What is the result?()
A

 Foo has the value of 0.

B

 Foo has the value of null.

C

 Foo has the value of true.

D

 Foo has the value of false.

E

 An exception is thrown.

F

 The code will not compile.


相似考题
更多“int index = 1;  boolean[] test = new Boolean[3];  boolean fo”相关问题
  • 第1题:

    boolean a=false;boolean b=true;boolean c=(a&&b)&&(!b);boolean result=(a&am

    boolean a=false; boolean b=true; boolean c=(a&&b)&&(!b); boolean result=(a&b)&(!b); 执行完后,正确的结果是( )。

    A.c=false;result=false

    B.c=true,result=true

    C.c=true;result=false

    D.c=false;result=true


    正确答案:A
    解析:本题考查Java中的运算。首先要清楚,“&&”是逻辑与运算符;“!”是逻辑非运算符;“&”是按位与运算符。按照逻辑运算符“a&&b”是false,“!b”是false,所以c是false。“a及b”是false,所以result是false。要注意区分“&&”和“&”,以及运算符之间的优先级关系,本题虽然没有涉及,但也要作为重点掌握。

  • 第2题:

    下列布尔变量定义中,正确并且规范的是

    A.BOOLEAN canceled=false;

    B.boolean canceled=false;

    C.boolean CANCELED=false;

    D.boolean canceled=FALSE;


    正确答案:B
    解析:本题考查Java的简单数据类型的变量定义及Java的命名约定。Java中的命名规则中包含如下几条:
      (1)变量名、方法名首单词小写,其余单词只有首字母大写;
      (2)常量完全大写;
      (3)变量命名采用完整的英文描述符,第一个字母小写,任何中间单词的首字母大写。
      Java语言区分大小写。简单数据类型布尔型用boolean表示。布尔型数据只有两个值: true(真)和false(假)。
      经过上述分析可知,选项B和选项C都能正确的定义一个布尔型变量,但是选项C的变量名CANCELED不符合Java中的命名规则,而选项B的变量名符合变量名的命名规则。因此,选项B是符合规范的布尔变量定义语句。
      本题的正确答案是选项B。

  • 第3题:

    下列代码的编译或执行结果是( )。 public class Myval{ public static void main(string args[]){ MyVal m=new MyVal; aMethod; } public void aMethod{ boolean b[]=new Boolean[5]; System.OUt.println(b[0]); } }

    A.1

    B.null

    C.0

    D.编译错误


    正确答案:A
    A。【解析】boolean类型的变量值只有ture或false,b[0]的默认初始值为false。

  • 第4题:

    在匹配器(Matcher)类中,用于输入字符串与模式串比较的方法是

    A.static boolean matches()

    B.boolean matcher,find()

    C.int matcher,start()

    D.int matcher,end()


    正确答案:A
    解析:本题考查对Java中的匹配器(Matcher)类的理解。Matcher类用于将一个输入字符串input和模式串pattern相比较。boolean matcher,find()方法用于寻找下一个模式匹配串:int matcher,start()方法用于返回匹配串的一个起始索引整数值:int matcher,end()方法用于返回匹配串的一个终止索引整数值。而用于输入字符串与模式串比较的方法是static boolean matches(),选项A正确。

  • 第5题:

    执行下列程序段之后,变量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。

  • 第6题:

    public class Test {  public static void main(String [] args) {  int x =5;  boolean b1 = true;  boolean b2 = false;  if((x==4) && !b2)  System.out.print(”l “);  System.out.print(”2 “);  if ((b2 = true) && b1)  System.out.print(”3 “);  } }  What is the result?() 

    • A、 2
    • B、 3
    • C、 1 2
    • D、 2 3
    • E、 1 2 3
    • F、 Compilation fails.
    • G、 Au exceptional is thrown at runtime.

    正确答案:D

  • 第7题:

    将有三个boolean值的数组初始化为true的是()

    • A、boolean[]b=newboolean[3]
    • B、"boolean[]b={true,true,true}"
    • C、"boolean[3]b={true,true,true}"
    • D、"boolean[]b=newboolean[3];b={true,true,true}"

    正确答案:B

  • 第8题:

    int index = 1;   boolean test = new Boolean;   boolean foo= test [index];  What is the result?()

    • A、 Foo has the value of 0.
    • B、 Foo has the value of null.
    • C、 Foo has the value of true.
    • D、 Foo has the value of false.
    • E、 An exception is thrown.
    • F、 The code will not compile.

    正确答案:D

  • 第9题:

    public class Key {  private long id1;  private long 1d2;  // class Key methods  }  A programmer is developing a class Key, that will be used as a key in a standard java.util.HashMap. Which two methods should be overridden to assure that Key works correctly as a key?()

    • A、 public int hashCode()
    • B、 public boolean equals(Key k)
    • C、 public int compareTo(Object o)
    • D、 public boolean equals(Object o)
    • E、 public boolean compareTo(Key k)

    正确答案:A,D

  • 第10题:

    单选题
    int index = 1;  boolean[] test = new Boolean[3];  boolean foo= test [index];   What is the result?()
    A

     Foo has the value of 0.

    B

     Foo has the value of null.

    C

     Foo has the value of true.

    D

     Foo has the value of false.

    E

     An exception is thrown.

    F

     The code will not compile.


    正确答案: A
    解析: 暂无解析

  • 第11题:

    单选题
    public class Test {  public static void main(String [] args) {  int x =5;  boolean b1 = true;  boolean b2 = false;  if((x==4) && !b2)  System.out.print(”l “);  System.out.print(”2 “);  if ((b2 = true) && b1)  System.out.print(”3 “);  } }  What is the result?()
    A

     2

    B

     3

    C

     1 2

    D

     2 3

    E

     1 2 3

    F

     Compilation fails.

    G

     Au exceptional is thrown at runtime.


    正确答案: G
    解析: 暂无解析

  • 第12题:

    多选题
    A JavaBeans component has the following field:  11. private boolean enabled;  Which two pairs of method declarations follow the JavaBeans standard for accessing this field?()
    A

    public void setEnabled( boolean enabled) public boolean getEnabled()

    B

    public void setEnabled( boolean enabled) public void isEnabled()

    C

    public void setEnabled( boolean enabled) public boolean isEnabled()

    D

    public boolean setEnabled( boolean enabled) public boolean getEnabled()


    正确答案: D,A
    解析: 暂无解析

  • 第13题:

    阅读下面程序 public class My Val{ public static void main(String args[]){ My Val m=new My Val(); m. amethod(); } public void amethod(){ boolean b[]=new Boolean[5]; } } 程序编译或运行结果是

    A.1

    B.null

    C.

    D.编译不能过


    正确答案:C
    解析:编译能通过,但不在控制台输出任何信息。程序只是实例化了一个布尔类型的数组,且由于此数组为局部变量,不会自动初始化,故其中值都为null。

  • 第14题:

    在匹配器(Matcher)类中,用于寻找下一个模式匹配串的方法是( )。 A.static boolean matchesSXB

    在匹配器(Matcher)类中,用于寻找下一个模式匹配串的方法是( )。

    A.static boolean matches

    B.boolean matcher.find

    C.int matcher.start

    D.int matcher.end


    正确答案:A
    A。【解析】本题考查考生对Java中的匹配器(Mateher)类的理解。Matcher类用于将一个输入字符串input和模式串pattern相比较。Booleanmateher.find方法用于寻找下一个模式匹配串;intmatcher.start方法用于返回匹配串的一个起始索引整数值;intmatcher.end方法用于返回匹配串的一个终止索引整数值。而用于输入字符串与模式串比较的方法是staticbooleanmatches,选项A正确。

  • 第15题:

    下列关于boolean类型的叙述中,正确的是( )。A.可以将boolean类型的数值转换为int类型的数值SX

    下列关于boolean类型的叙述中,正确的是( )。

    A.可以将boolean类型的数值转换为int类型的数值

    B.可以将boolean类型的数值转换为字符串

    C.可以将boolean类型的数值转换为char类型的数值

    D.不能将boolean类型的数值转换为其他基本数据类型


    正确答案:D
    由于基本数据类型中boolean类型不是数字型,所以基本数据类型的转换是除了boolean类型以外的其他7种类型之间的转换。

  • 第16题:

    当执行下面代码时,会输出( )。 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。

  • 第17题:

    下面哪些语句是没有编译错误的()

    • A、StringBuffer sb=“java”;
    • B、inti=0x56;
    • C、Boolean b=new Boolean(“java”);
    • D、float f=1.0;

    正确答案:B,C

  • 第18题:

    int i,j; boolean booleanValue=(i==j)。


    正确答案:错误

  • 第19题:

    Which determines if “prefs” is a directory and exists on the file system?()  

    • A、 Boolean exists=Directory.exists (“prefs”);
    • B、 Boolean exists=(new File(“prefs”)).isDir();
    • C、 Boolean exists=(new Directory(“prefs”)).exists();
    • D、 Boolean exists=(new File(“prefs”)).isDirectory();
    • E、 Boolean exists=true;  Try{  Directory d = new Directory(“prefs”);  } catch (FileNotFoundException e) {  exists = false;  }

    正确答案:D

  • 第20题:

    Given:  8.int index = 1:  9.Boolean [] test = new boolcan [3];  10.boolcan foo = test [index];   What is the result()?  

    • A、 foo has the value of 0.
    • B、 foo has the value of null.
    • C、 foo has the value of true.
    • D、 foo has the value of false.
    • E、 An-exception is thrown.
    • F、 The code will not compile.

    正确答案:D

  • 第21题:

    int index = 1;  boolean[] test = new Boolean[3];  boolean foo= test [index];   What is the result?()  

    • A、 Foo has the value of 0.
    • B、 Foo has the value of null.
    • C、 Foo has the value of true.
    • D、 Foo has the value of false.
    • E、 An exception is thrown.
    • F、 The code will not compile.

    正确答案:D

  • 第22题:

    单选题
    int index = 1;   boolean test = new Boolean;   boolean foo= test [index];  What is the result?()
    A

     Foo has the value of 0.

    B

     Foo has the value of null.

    C

     Foo has the value of true.

    D

     Foo has the value of false.

    E

     An exception is thrown.

    F

     The code will not compile.


    正确答案: F
    解析: 暂无解析

  • 第23题:

    单选题
    Which determines if “prefs” is a directory and exists on the file system?()
    A

     Boolean exists=Directory.exists (“prefs”);

    B

     Boolean exists=(new File(“prefs”)).isDir();

    C

     Boolean exists=(new Directory(“prefs”)).exists();

    D

     Boolean exists=(new File(“prefs”)).isDirectory();

    E

     Boolean exists=true;  Try{  Directory d = new Directory(“prefs”);  } catch (FileNotFoundException e) {  exists = false;  }


    正确答案: C
    解析: 暂无解析

  • 第24题:

    单选题
    Given:  8.int index = 1:  9.Boolean [] test = new boolcan [3];  10.boolcan foo = test [index];   What is the result()?
    A

     foo has the value of 0.

    B

     foo has the value of null.

    C

     foo has the value of true.

    D

     foo has the value of false.

    E

     An-exception is thrown.

    F

     The code will not compile.


    正确答案: F
    解析: 暂无解析