题目内容

以下程序的输出结果为:()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. 运行时异常

以下程序的输出结果为:()class s implements Runnable{int x, y;public void run(){for(int i = 0; i < 1000; i++)synchronized(this){x = 12;y = 12;}System.out.print(x + " " + y + " ");}public static void main(String args[]){s run = new s();Thread t1 = new Thread(run);Thread t2 = new Thread(run);t1.start();t2.start();}}

A. 死锁
B. 12 12 12 12
C. 编译错误
D. 没有输出

以下程序的输出结果为:()public class NFE{public static void main(String [] args){String s = "42";try{s = s.concat(".5");/* Line 8 */double d = Double.parseDouble(s);s = Double.toString(d);int x = (int) Math.ceil(Double.valueOf(s).doubleValue());System.out.println(x);}catch (NumberFormatException e){System.out.println("bad number");}}}

A. 42
B. 42.5
C. 43
D. bad number

答案查题题库