SCJP程序员认证考试

单选题public void foo( boolean a, boolean b ){  if( a ) {  System.out.println( “A” );  } else if ( a && b ) {  System.out.println( “A&&B” );  } else { 17. if ( !b ) {  System.out.println( “notB” );  } else {  System.out.println( “ELSE” );  }  } }  What is co

题目
单选题
public void foo( boolean a, boolean b ){  if( a ) {  System.out.println( “A” );  } else if ( a && b ) {  System.out.println( “A&&B” );  } else { 17. if ( !b ) {  System.out.println( “notB” );  } else {  System.out.println( “ELSE” );  }  } }  What is correct?()
A

 If a is true and b is true then the output is “A&&B”.

B

 If a is true and b is false then the output is “notB”.

C

 If a is false and b is true then the output is “ELSE”.

D

 If a is false and b is false then the output is “ELSE”.

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

第1题:

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

第2题:

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

第3题:

【Java代码】

import Java.util.ArrayList;

import java.util.List;

(1) class AbstractFile{

protected String name;

public void printName(){System.out.println(name);}

public abstract boolean addChild(AbstractFile file);

public abstract boolean removeChild(AbstractF ile file);

public abstract List<AbstractFile> getChildren();

class File extends AbstractFile{

public File(String name){this.name=name;}

public boolean addChild(AbstractFile file){return false;}

public boolean removeChild(AbstractFile file){return false;}

public List<AbstractFile> getChildren(){return (2) ;}

class Folder extends AbstractFile{

private List <AbslractFile> childList;

public Folder(String name){

this.name=name;

this.childList=new ArrayList<AbstractFile>();

public boolean addChild(AbstractFile file) { return childList.add(file);}

public boolean removeChild(AbstractFile file){return childList.remove(file);}

public (3) <AbstractFile> getChildren(){return (4) ;}

public class Client{

public static void main(String[] args){

//构造一个树形的文件/目录结构

AbstractFile rootFolder= new Folder("c:\\ ");

AbstractFile compositeFolder=new Folder("composite");

AbstractFile windowsFolder=new Folder("windows");

AbstractFile file=new File("TestComposite.java");

rootFolder.addChild(compositeFolder) ;

rootFolder.addChild(windowsFolder);

compositeFolder.addChild(file) ;

//打印目录文件树

printTree(rootFolder);

private static void printTree(AbslractFile ifile){

ifile.printName();

List <AbslractFile> children=ifile.getChildreno:

if(children==null) return;

for (AbstractFile file:children) {

(5) ;

}

该程序运行后输出结果为:

c:\

composite

TestComposite.java

Windows


正确答案:
(1)abstract
(2)null
(3)List
(4)childList
(5)printTree(file)

第4题:

以下哪个方法可以用来获得进度条的当前进度值?()

  • A、public synchronized int getProgress()
  • B、public synchronized void setIndeterminate (boolean indeterminate)
  • C、public synchronized void setProgress(int progress)
  • D、Public final synchronized void incrementProgressBy(int diff)

正确答案:A

第5题:

以下哪个是Java应用程序main方法的有效定义?

A. public static void main();

B. public static void main( String args );

C. public static void main( String args[] );

D. public static void main( Graphics g );

E. public static boolean main( String a[] );


正确答案:C

第6题:

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

第7题:

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

第8题:

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

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

第9题:

public void foo( boolean a, boolean b ){  if( a ) {  System.out.println( “A” );  } else if ( a && b ) {  System.out.println( “A&&B” );  } else { 17. if ( !b ) {  System.out.println( “notB” );  } else {  System.out.println( “ELSE” );  }  } }  What is correct?()  

  • A、 If a is true and b is true then the output is “A&&B”.
  • B、 If a is true and b is false then the output is “notB”.
  • C、 If a is false and b is true then the output is “ELSE”.
  • D、 If a is false and b is false then the output is “ELSE”.

正确答案:C

第10题:

public class test (   private static int j = 0;     private static boolean methodB(int k) (  j += k;    return true;   )    public static void methodA(int i) {    boolean b:   b = i < 10 | methodB (4);    b = i < 10 || methodB (8);   )     public static void main (String args) } (    methodA (0);  system.out.printIn(j);   )    )   What is the result?()  

  • A、 The program prints “0”
  • B、 The program prints “4”
  • C、 The program prints “8”
  • D、 The program prints “12”
  • E、 The code does not complete.

正确答案:B

更多相关问题