public static void main(String[] args) {
ArrayList myList=new ArrayList();
String[] myArray;
try{
while (true){
myList.add(“My String”);//死循环 内存溢出
}
}
catch (RuntimeException re) { System.out.println(“Caught a RuntimeException”); } catch (Exception e) { System.out.println(“Caught an Exception”); } System.out.println(“Ready to use”);}
答案:C解析:
A.Execution terminates in the first catch statement, and caught a RuntimeException is printed to the console.执行在第一个catch语句中终止,并且捕获到一个运行时异常被打印到控制台
B.Execution terminates In the second catch statement, and caught an Exception is printed to the console.执行在第二个catch语句中终止,并且catch异常被打印到控制台。
C.A runtime error is thrown in the thread “main”.线程“main”中引发运行时错误。
D.Execution completes normally, and Ready to us is printed to the console.执行正常完成,准备就绪打印到控制台。
E.The code fails to compile because a throws keyword is required.代码无法编译,因为需要一个throws关键字
考题笔记
最新推荐文章于 2023-01-08 09:53:52 发布