String foo = “blue”;  Boolean[]bar = new Boolean [1];  if (b

题目
单选题
String foo = “blue”;  Boolean[]bar = new Boolean [1];  if (bar[0])  {  foo = “green”;  }   What is the result? ()
A

 Foo has the value of “”

B

 Foo has the value of null.

C

 Foo has the value of “blue”

D

 Foo has the value of “green”

E

 An exception is thrown.

F

 The code will not compile.

如果没有搜索结果或未解决您的问题,请直接 联系老师 获取答案。
相似问题和答案

第1题:

Stringfoo=blue”;Boolean[]bar=newBoolean[1];if(bar[0]){foo=green”;}Whatistheresult?()

A.Foohasthevalueof“”

B.Foohasthevalueofnull.

C.Foohasthevalueof“blue”

D.Foohasthevalueof“green”

E.Anexceptionisthrown.

F.Thecodewillnotcompile.


参考答案:F

第2题:

阅读下面程序 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。

第3题:

下列代码的编译或执行结果是______。

public class MyVal{

puhlic static void main(String args[]){

MyVal m=new MyVal();

m.aMethod();

}

public void aMethod(){

boolean b[]=new Boolean[5];

System.out.println(b[0]);

}

A) 1

B) null

C) 0

D) 编译错误

A.

B.

C.

D.


正确答案:B

第4题:

public class Delta {  static boolean foo(char c) {  System.out.print(c);  return true;  }  public static void main( String[] argv ) {  int i =0;  for ( foo(‘A’); foo(‘B’)&&(i<2); foo(‘C’)){  i++ ;  foo(‘D’);  }  }  }  What is the result?()  

  • A、 ABDCBDCB
  • B、 ABCDABCD
  • C、 Compilation fails.
  • D、 An exception is thrown at runtime.

正确答案:A

第5题:

public class Test {   public static void main (String args) {  string foo = “blue”;  string bar = foo;   foo = “green”;   System.out.printIn(bar);   }   }   What is the result?()  

  • A、 An exception is thrown.
  • B、 The code will not compile.
  • C、 The program prints “null”
  • D、 The program prints “blue”
  • E、 The program prints “green”

正确答案:D

第6题:

Given:Which code, inserted at line 15, allows the class Sprite to compile?()

A.Foo { public int bar() { return 1; }

B.new Foo { public int bar() { return 1; }

C.new Foo() { public int bar() { return 1; }

D.new class Foo { public int bar() { return 1; }


参考答案:C

第7题:

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

第8题:

publicclassTest{publicstaticvoidmain(String[]args){stringfoo=blue”;stringbar=foo;foo=green”;System.out.printIn(bar);}}Whatistheresult?()

A.Anexceptionisthrown.

B.Thecodewillnotcompile.

C.Theprogramprints“null”

D.Theprogramprints“blue”

E.Theprogramprints“green”


参考答案:D

第9题:

class Sock2 {   String color;   public boolean equals(Object o) {   return color.equals(((Sock2)o).color);   } }   class TestSocks {   public static void main(String [] args) {   Sock2 s1 = new Sock2(); s1.color = "blue";   Sock2 s2 = new Sock2(); s2.color = "blue";   if (s1.equals(s2)) System.out.print("equals ");   if (s1 == s2) System.out.print("== ");   }   }   结果为:()      

  • A、==
  • B、equals
  • C、equals ==
  • D、无结果输出

正确答案:B

第10题:

Which statements concerning the relationships between the following classes are true?()   class Foo {  int num;   Baz comp = new Baz();   }   class Bar {  boolean flag;   }   class Baz extends Foo {   Bar thing = new Bar();   double limit;   }  

  • A、A Bar is a Baz.
  • B、A Foo has a Bar.
  • C、A Baz is a Foo.
  • D、A Foo is a Baz.
  • E、A Baz has a Bar.

正确答案:C,E

更多相关问题