15 正确的说法是__A____。
A、编译时将产生错误 B、编译时正确,运行时将产生错误 C、输出为零 D、输出为空
解析:由于数组arr声明时未用static关键字,而main()方法直接引用arr(而非通过Person的实例引用),将产生"非静态变量不能从静态上下文中引用"(non-static variable cannot be referenced from a static context)的编译错误。
16 某二叉树中度为2的结点有18个,则该二叉树中有 19 个叶子结点。
解析:二叉树的性质3:在任意一棵二叉树中,度为0的结点(即叶子结点)总是比度为2的结点多一个。本题中度为2的结点数为18,故叶子结点数为18+1=19个。
17 问题处理方案的正确而完整的描述称为 算法 。
18 线程在生命周期中要经历5种状态,分别是新建状态、可运行状态、运行状态、___阻塞 或 Blocked___状态和终止状态。
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之间的小数。