题目内容

以下程序的输出结果为:()class BoolArray{boolean [] b = new boolean[3];int count = 0;void set(boolean [] x, int i){x[i] = true;++count;}public static void main(String [] args){BoolArray ba = new BoolArray();ba.set(ba.b, 0);ba.set(ba.b, 2);ba.test();}void test(){if ( b[0] && b[1] | b[2] )count++;if ( b[1] && b[(++count - 2)] )count += 7;System.out.println("count = " + count);}}

A. count = 0
B. count = 2
C. count = 3
D. count = 4

查看答案
更多问题

public void foo( boolean a, boolean b){if( a ){System.out.println("A"); /* Line 5 */}else if(a && b) /* Line 7 */{System.out.println( "A && B");}else /* Line 11 */{if ( !b ){System.out.println( "notB") ;}else{System.out.println( "ELSE" ) ;}}}

A. If a is true and b is true then 输出 "A && B"
B. If a is true and b is false then 输出 "notB"
C. If a is false and b is true then 输出 "ELSE"
D. If a is false and b is false then 输出 "ELSE"

以下程序的输出结果为:()public class Test{public static void aMethod() throws Exception{try/* Line 5 */{throw new Exception();/* Line 7 */}finally/* Line 9 */{System.out.print("finally ");/* Line 11 */}}public static void main(String args[]){try{aMethod();}catch (Exception e) /* Line 20 */{System.out.print("exception ");}System.out.print("finished");/* Line 24 */}}

A. finally
B. exception finished
C. finally exception finished
D. Compilation fails

class X implements Runnable{public static void main(String args[]){/* Missing code? */}public void run() {}}哪一行代码适合启动线程?

A. Thread t = new Thread(X);
B. Thread t = new Thread(X);t.start();
C. X run = new X();Thread t = new Thread(run);t.start();
D. Thread t = new Thread();x.run();

以下程序的输出结果为:()class MyThread extends Thread{MyThread() {}MyThread(Runnable r) {super(r); }public void run(){System.out.print("Inside Thread ");}}class MyRunnable implements Runnable{public void run(){System.out.print(" Inside Runnable");}}class Test{public static void main(String[] args){new MyThread().start();new MyThread(new MyRunnable()).start();}}

A. 输出 "Inside Thread Inside Thread"
B. 输出 "Inside Thread Inside Runnable"
C. 不会编译
D. 运行时异常

答案查题题库