栏目分类:
子分类:
返回
终身学习网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
终身学习网 > IT > 面试经验 > 笔试题库

[填空题] 请阅读下列程序代码,然后将程序的执行结果补充完整。程序代码:public class throwsException{static void Proc(int sel)throws Ari

笔试题库 更新时间:发布时间: 百科书网 趣学号

[填空题] 请阅读下列程序代码,然后将程序的执行结果补充完整。程序代码:public class throwsException{static void Proc(int sel)throws ArithmeticException,ArrayIndexOutOfBoundsException{System.out.println("In Situation"+sel);if(sel==0){System.out.println("no Exception caught");return;}else if(sel==1){int iArray[]=new int[4];iArray[1]=3;}}public static void main(String args[]){try{Proc(0);Proc(1)}catch(ArrayIndexOutOfBoundsException e){System.out.println("Catch"+e);}finally{System.out.println("in Proc finally");}}}执行结果:In、Situation 0no Exception caught()in Proc finally

正确答案:

InSituationl

参考解析:

本题考查考生阅读Java程序的能力。题目程序看似复杂,但流程非常简单。程序的public类是throwsException,类中定义了Proc(intsel)方法。程序入口是main()方法,使用try-catch-finally来捕获ArithmeticException和ArrayIndexOutOfBounds- Exception异常,这两个异常是关于算术异常或数组索引越界的异常。执行Proc(0)时,输出In Situation 0 和no Exception caught两条信息;执行Proc(1)时,输出In Situationl和in Proc finally两条信息。整个程序并未发生异常。

转载请注明:文章转载自 www.051e.com
本文地址:http://www.051e.com/it/587079.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 ©2023-2025 051e.com

ICP备案号:京ICP备12030808号