计算机等级考试二级Java练习题及解析(7)

出处:考试大 作者:wyl 日期:2007年07月18日 14时07分
       

19  请阅读下列程序代码,然后将程序的执行结果补充完整。
程序代码:
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 Situation0
no Exception caught
__In Situation1____
in Proc finally

解析:调用Proc(1)时,执行语句System.out.println("In Situation"+sel);控制台输出In Situation1。然后在if语句中执行sel==1分支,该分支中无任何输出语句。
当使用Thread t=new Thread(r)创建一个线程时,表达式:r instanceof Thread的值是___false___。
表达式:r instanceof Thread的语义即"r是否为Thread的实例(instance)"。再看Thread的构造方法(Thread有许多构造方法,以下是最典型的构造方法,其它构造方法都是从下面的构造方法中"减掉"一些参数形成的):
    Thread(ThreadGroup group, Runnable target, String name) 
可见,Thread构造方法中没有类型为Thread的参数,故r不可能是Thread的实例
20  面向对象的语言将客观世界都看成由各种对象组成。具有共同特征和行为的对象组成类,类是变量和___操作___的集合体。
21   Random类中的nextInt(N)方法得到一个介于0至N-1之间的随机数,而平常用到的Math.random()是得到一个介于0与1之间的小数。

最后更新时间:2008-05-28 12:02:48
文章评论
共有 0 位网友发表了评论
用户名: 新注册) 密码: 匿名评论 [查看所有评论]

评论内容:(不能超过250字,需审核后才会公布,请自觉遵守互联网相关政策法规。
您可以用以下几种方式找到此文章

考试全流程