网友您好, 请在下方输入框内输入要搜索的题目:

题目内容 (请给出正确答案)
单选题
阅读下列程序片段: public void test(){ try{ sayHello(); System.out.println("hello"); } catch(ArrayIndexOutOfBoundException e){ System.out.println("ArrayIndexOutOfBoundException"); } catch(Exception e){ System.out.println("Exception"); } finally{ System.out.println("finally"); } }如果sayHello()方法正常运行,则test()方法的运行结果将是(  )。
A

hello

B

ArrayIndexOutOfBoundException

C

Exception
  finally

D

hello
  finally


参考答案

参考解析
解析:
因为方法sayHello()正常运行,而且语句System.out.println("hello")也没有异常抛出,所以两个catch语句捕获不到异常,因此执行finally子句,输出“finally”。另外,捕获异常的统一出口通过finally从句,因此对catch而言,无论由哪个捕获异常,最后一定执行finally从句,保证控制流在转到其他路径以前,程序的状态能被统一管理。需要注意的是,在系统执行时,遇到异常就自动跳转,异常语句后面的程序就不被执行。
更多 “单选题阅读下列程序片段: public void test(){ try{ sayHello(); System.out.println("hello"); } catch(ArrayIndexOutOfBoundException e){ System.out.println("ArrayIndexOutOfBoundException"); } catch(Exception e){ System.out.println("Exception"); } finally{ System.out.println("finally"); } }如果sayHello()方法正常运行,则test()方法的运行结果将是(  )。A helloB ArrayIndexOutOfBoundExceptionC Exception finallyD hello finally” 相关考题
考题 下列程序的运行结果是public class test{private String[] data={“10”,“10.5”};public void fun(){double s=0;for(int i=0;i3;i++){try{s=s+Integer .parseInt(data[i]);}catch(Exception e){System.out.print(“errorl:”+data[i]);}}}public static void main(String[]args){try{testd=new test();d .fun();}catch(Exception e){System.out.printIn(“error2”);}}}A.errorl:10.5B.error2C.errorl:10.5 error2D.以上都不对

考题 下列程序片段中,能通过编译的是A.public abstract class Animal{ public void speak();}B.public abstract class Animal{ public void speak(){}}C.public class Animal{ public abstract void speak();}D.public abstract class Animal{ public abstract void speak(){}}

考题 阅读下列程序片段。Public void test{Try{sayHello;system.out.println(hello):}catch(ArraylndexOutOfBoundException e){System.out.println(ArraylndexOutOfBoundExcep—tion);}catch(Exception e){System.out.println(Exception):}finally{System.Out.println(finally);}}如果sayHello方法正常运行,则test方法的运行结果将是( )。A.HelloB.ArraylndexOutOfBondsExceptionC.ExceptionFinallyD.HelloFinally

考题 ( 28 )阅读下面程序1 public class Try extends Thread{2 public static void main(String args[ ]){3 Try t = new Try( );4 t.start( );5 }67 public void run( int j){8 int i = 0;9 while(i5){10 System.out.println(" 祝你成功! ");11 i++;12 }13 }14 }该程序要求打印 5 行 “ 祝你成功! ” ,必须改正程序中的某行代码,程序才能完成。选择正确的修改是A )将第 1 行的 extends Thread 改为 implements RunnableB )将第 3 行的 new Try() 改为 new Thread()C )将第 4 行 t.start() 改为 start(t)D )将第 7 行的 public void run( int j) 改为 public void run()

考题 阅读下面程序class Test implements Runnable{public static void main(String[] args){Test t = new Test();t.start();}public void run(){ }}下列关于上述程序的叙述正确的是A) 程序不能通过编译,因为 start() 方法在 Test 类中没有定义B) 程序编译通过,但运行时出错,提示 start() 方法没有定义C) 程序不能通过编译,因为 run() 方法没有定义方法体D) 程序编译通过,且运行正常

考题 下列关于Test类的定义中,正确的是______。A) class Test implements Runnabte{public void run(){}public void someMethod(){}B) class Test implements Rnuuable{public void run();}C) class Test implements Rnuuable{public void someMethod();}D) class Test implements Rnuuable{public void someMethod();{}}A.B.C.D.

考题 阅读下面程序 public class Test2______ { public static void main(String[] args){ Thread t=new Test2(); t. start(); } public void run(){ System. out. priatln("How are you. "); } } 在程序下画线处填入的正确的选项是A.implements ThreadB.extends RunnableC.implements RunnableD.extends Thread

考题 阅读下面程序 public class Test implements Runnable{ public static void main(String[]args){ _______________________________________; t. start(); } public void mR(){ System. out. println("Hello!"); }} 在程序下画线处填入正确选项是A.Test t=flew Test()B.Thread t=new Thread();C.Thread t=new Thread(new Test());D.Test t=new Thread();

考题 阅读下面程序 1 public class Try extends Thread { 2 public static void main(String args[]) { 3 Try t=new Try(); 4 t.start(); 5 } 6 7 public void run(int j) { 8 int i=0; 9 while(i<5) { 10 System.out.println("祝你成功!"); 11 i++: 12 } 13 } 14 } 该程序若能打印5行“祝你成功!”,必须改正程序中的某行代码,选择正确的修改是A.将第1行的extends Thread改为implements RunnableB.将第3行的new Try()改为new Thread()C.将第4行的t.start()改为start(t)D.将第7行的public void run(int j)改为public void run()

考题 阅读下面程序 class Test implements Runnable { public static void main(String[] args) { Test t=new Test(); t.start(): } public void run() {} } 下列关于上述程序的叙述正确的是A.程序不能通过编译,因为start()方法在Test类中没有定义B.程序编译通过,但运行时出错,提示start()方法没有定义C.程序不能通过编译,因为run()方法没有定义方法体D.程序编译通过,且运行正常

考题 下列程序片段中,能通过编译的是( )。A.public abstract class Animal{public void speak( );}B.public abstract class Animal{public void speak( ){};}C.public class Animal{pubilc abstract void speak( );}D.public abstract class Animal{pubile abstract void speak( ){};}

考题 下列程序创建了一个线程并运行,横线处应填入的正确代码是( )。 public class Try extends Thread{ public static void main(String args[]){ Thread t=new Try; ; } public void runf System.out.println(”Try!"); } }A.t.startB.t.classC.t.threadD.t.static

考题 下列程序的运行结果是( )。 public class test{ private String[]data={¨10","10.5"); public void fun{ double s=0: for(int i=0;i3;j++){ try{ s=s+Integer.parseInt(data[i]); catch(Exception e){ System.out.print("errorl:"+data[i]); } } } public static void main(string[]args){ try{ test d=new test: fun: }catch(Exception e){ System.OUt.println("error2") } } }A.errorl:10.5B.error2C.errorl:10.5 error2D.以上都不对

考题 下列程序的功能是在监控台上每隔一秒钟显示一个字符串”Hello!”,能够填写在程序中下画线位置,使程序完整并能正确运行的语句是( )。 public class Test implements Runnable{ public static void main(String args[]){ Test t=new Test: Threadt t=new Thread(t); tt.start: } public void run{ for(;;){ try{ ; }catch(e){} System.out.println("Hello"); } } }A.sleep(1000)B.t.sleep(1000)InterruptedExceptionInterruptedExceptionC.Thread.sleep(1000)D.Thread.sleep(1000)RuntimeExceptionInterruptedException

考题 阅读下列程序片段。 Public void test{ Try{ sayHello; system.out.println("hello"): }catch(ArraylndexOutOfBoundException e){ System.out.println("ArraylndexOutOfBoundExcep— tion"); }catch(Exception e){ System.out.println("Exception"): }finally{ System.Out.println("finally"); } } 如果sayHello方法正常运行,则test方法的运行结果将是( )。A.HelloB.ArraylndexOutOfBondsExceptionC.Exception FinallyD.Hello Finally

考题 阅读下列程序片段。如果sayHello( )方法正常运行,则test( )方法的运行结果将是( )。A.HelloB.ArrayIndexOutOfBondsExceptionC.ExceptionFinallyD.HelloFinally

考题 阅读下列程序片段 Publicvoidtest(){ Try{ sayHello(); system.out.println(“hello"); }catch(ArrayIndexOutOfBoundExceptione){ System.out.println(“ArraylndexOutOfBoundException”); }catch(Exceptione){ System.out.println(“Exception”); }finally{ System.out.println(“finally”); } } 如果sayHello()方法正常运行,则test()方法的运行结果将是( )。A.HelloB.ArraylndexOutOfBondsExceptionC.Exception FinallyD.Hello Finally

考题 阅读下面程序 public class Test2 ______ { public static void main(String[] args) { Thread t=new Test2(); t.start(); } public void run() { System.out.println("How are you."); } } 程序中下画线处应填入的正确选项是A.implements ThreadB.extends RunnableC.implements RunnableD.extends Thread

考题 下列程序片段中,能通过编译的是( )。 A.public abstract class Animal{ public void speak;}S 下列程序片段中,能通过编译的是( )。A.public abstract class Animal{ public void speak;}B.public abstract class Animal{ public void speak{);}C.public class Animal{ pubilc abstract void speak;}D.public abstract class Animal{ pubile abstract void speak{};}

考题 阅读下面的程序public class Test {public static void main(String[] args) {for(int x = 0 ; x A.跳出循环,无输出B.0121C.01D.0123

考题 下列程序创建了一个线程并运行,请在下划线处填入正确代码。public class Try extends Thread{public static void main(String args[]){Threadt=new Try();【 】;}public void run(){System.out.println(“Try!”);}}

考题 以下语句能顺利通过编译: class test { static void sayHello() { this.toString(); } public String toString() { retur。() 此题为判断题(对,错)。

考题 static void test() throws RuntimeException {  try {  System.out.print(”test “);  throw new RuntimeException();  }  catch (Exception ex) { System.out.print(”exception “); }  }  public static void main(String[] args) {  try { test(); }  catch (RuntimeException ex) { System.out.print(”runtime “); }  System.out.print(”end “);  }  What is the result?() A、 test endB、 Compilation fails.C、 test runtime endD、 test exception endE、 A Throwable is thrown by main at runtime.

考题 public class Test {  public static void aMethod() throws Exception {  try {  throw new Exception(); } finally {  System.out.println(“finally”);  }  }  public static void main(String args[]) {  try {  aMethod();  } catch (Exception e) {  System.out.println(“exception”);  }  System.out.println(“finished”);  }  }  What is the result?()  A、 finallyB、 exception finishedC、 finally exception finishedD、 Compilation fails.

考题 public class Test {} What is the prototype of the default constructor?()  A、 Test()B、 Test(void)C、 public Test()D、 public Test(void)E、 public void Test()

考题 单选题下列程序的运行结果是(  )。public class test{private String [] data = {"10","10.5"};public void fun(){ double s = 0; for(int i = 0; i try{ s = s + Integer.parseInt(data[i]); } catch(Exception e){ System.out.print("error1:" + data[i]); } }}public static void main(String[] args){ try{ test d = new test(); d.fun(); } catch(Exception e){ System.out.println("error2"); }} }A error1:10.5B error2C error1:10.5error2D 以上都不对

考题 单选题编译如下的Java程序片段:  Class test{     Int count=9;     Public void a(){   Int count=10;   System.out,println(“count 1=” + count); }  Public void count(){   System.out.println(“count 2 =”+ count); }  Public static void main(String args[] ){   Test t=new Test();   t.a();   t.count(); } }  结果是()A 不能通过编译B 输出:count 1 =10  count 2=9C 输出:count 1=9 count 2=9

考题 单选题public class Test {} What is the prototype of the default constructor?()A  Test()B  Test(void)C  public Test()D  public Test(void)E  public void Test()