• 2022-06-08
    阅读以下程序class Test{static void F(){try{G();}Catch(Exception e){Console.Write(e.Message);e = new Exception(“F”);throw;}}static void G(){throw new Exception(“G”);}static void Main(){try{F();}catch(Exception e){Console.Write (e.Message);}}}以上程序运行的结果是()
    A: F F
    B: F G
    C: G G
    D: G F
  • C

    举一反三

    内容

    • 0

      读程序,写出和程序输出格式一致的输出结果。 public class J_Test { public static void mb_method(int i) { try { if(i == 1) throw new Exception(); System.out.print("1"); } catch(Exception ex) { System.out.print("2"); return; } finally { System.out.print("3"); } System.out.print("4"); } public static void main(String[] args) { mb_method(0); mb_method(1); } }

    • 1

      import java.io.IOException;  public class ExceptionTest(  public static void main (String[]args)  try (  methodA();  ) catch (IOException e)  (  system.out.printIn(“Caught IOException”);  ) catch (Exception e)   (  system.out.printIn(“Caught Exception”);  )  )  public void methodA ()   {  throw new IOException ();  }   What is the result?() A:  The code will not compile. B:  The output is caught exception. C:  The output is caught IOException. D:  The program executes normally without printing a message.

    • 2

      下列程序中注释的那个代码是错误的? abstract class Takecare{ protected void speakHello() {} public abstract static void cry(); static int f(){return 0;} abstract float g(); } A: protected void speakHello() {} B: public abstract static void cry(); C: static int f(){return 0;} D: abstract float g();

    • 3

      检查下面的代码: class E1 extends Exception{ } class E2 extends E1 { } public class Test{ public static void main(String[] args){ try{ throw new E1( ); } // --X-- } }下列语句,哪些可以放到--X--位置,而且保证编译成功。 A: catch(Exception x){ } B: catch(Test x) { } C: catch(E1 x){ } D: catch(E2 x){ }

    • 4

      阅读下面的代码段,屏幕的输出是什么?public static void main(String[] args) { try{tryThis();return;}catch(IOException x1){ System.out.println("exception 1");return;}catch(Exception x2){System.out.println("exception 2");return;}finally{ System.out.println("finally");} } static void tryThis() throws IOException{ throw new IOException(); } A: ”exception1”后面跟着”finally” B: ” exception2”后面跟着“finally” C: ”exception1” D: ”exception2”