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之间的小数。
转贴于:计算机二级考试_考试大
【责编:wyl 纠错】
[1] [2] [3]