Java |异常处理|问题1

预测以下Java程序的输出

null

class Main {
public static void main(String args[]) {
try {
throw 10 ;
}
catch ( int e) {
System.out.println( "Got the  Exception " + e);
}
}
}


(A) 有例外10 (B) 得到了异常0 (C) 编译错误 答复: (C) 说明: 在Java中,只有throwable对象(throwable对象是throwable类的任何子类的实例)可以作为异常抛出。所以根本不能抛出基本数据类型。

以下是上述程序中的错误

Main.java:4: error: incompatible types
         throw 10;
               ^
  required: Throwable
  found:    int
Main.java:6: error: unexpected type
      catch(int e) {
            ^
  required: class
  found:    int
2 errors

这个问题的小测验

© 版权声明
THE END
喜欢就支持一下吧
点赞14 分享