大学MOOC Java语言程序设计(华东交通大学)1205828824 最新慕课完整章节测试答案
异常处理
异常处理单元测验
1、单选题:
以下程序段执行时输入:java Test 则输出结果为( )。class Test { public static void main(String args[ ]) { System.out.println(args[0]); }}
选项:
A: 无任何输出
B: 产生数组访问越界异常
C: 输出 0
D: 输出 Test
答案: 【 产生数组访问越界异常】
2、单选题:
设有如下代码:try { tryThis(); return; } catch (IOException x1) { System.out.println("exception 1"); return; } catch (Exception x2) { System.out.println("exception 2"); return; } finally { System.out.println("finally");} 如果 tryThis() 抛出 NumberFormatException,则输出结果包括( )
选项:
A: "exception 1"
B: "exception 1", 后跟 "finally"
C: "exception 2", 后跟 "finally"
D: "exception 2"
答案: 【 "exception 2", 后跟 "finally" 】
3、单选题:
设有如下代码段:#1 String s = null;#2 if ( s != null & s.length() > 0)#3 System.out.println("s != null & s.length() > 0");#4 if ( s != null && s.length() > 0)#5 System.out.println("s != null & s.length() > 0");#6 if ( s != null || s.length() > 0)#7 System.out.println("s != null & s.length() > 0");#8 if ( s != null | s.length() > 0)#9 System.out.println("s != null | s.length() > 0");将抛出空指针异常的行是( )。
选项:
A: 2、4
B: 6、8
C: 2、4、6、8
D: 2、6、8
答案: 【 2、6、8 】
4、多选题:
设有一个串s,和一个int型变量i,以下那条语句可能产生异常?
选项:
A: if ((s !=null) && ( i ==s.length()))
B: if ((s ==null) && ( i ==s.length()))
C: if ((s !=null) || ( i ==s.length()))
D: if ((s ==null) || ( i ==s.length()))
答案: 【 if ((s ==null) && ( i ==s.length())) ;
if ((s !=null) || ( i ==s.length()))】
5、多选题:
设有如下代码: class Base{ public void amethod(int i) { } } public class Scope extends Base{ public static void main(String argv[]){ } //Method Here }以下哪个方法可插入//Method 处?
选项:
A: public void amethod(int i) throws Exception {}
B: public void amethod(int i) { }
C: public void amethod(long i) { }
D: public void amethod(long i) throws Exception {}
答案: 【 public void amethod(int i) { };
public void amethod(long i) { };
public void amethod(long i) throws Exception {} 】
6、多选题:
关于try..catch..finally执行机制的描述,以下叙述那个正确?
选项:
A: 每个try 块必须至少跟一个catch块.
B: 一个try 块可跟任意个finally块.
C: 一个try块必须至少跟一个finally 或 catch块.
D: 如果catch 和 finally块均有,则catch 必须先于finally.
答案: 【 一个try块必须至少跟一个finally 或 catch块. ;
如果catch 和 finally块均有,则catch 必须先于finally. 】
抽象类、接口及内嵌类
抽象类与接口测验
1、单选题:
以下程序的调试结果为( )。public class Outer{ public String name = "Outer"; public static void main(String argv[]){ Inner i = new Inner(); i.showName(); } private class Inner{ String name = new String("Inner"); void showName(){ System.out.println(name); } }}
选项:
A: 输出结果 Outer
B: 输出结果 Inner
C: 编译错误,因 Inner 类定义为私有访问
D: 在创建 Inner 类实例的行出现编译错误
答案: 【 在创建 Inner 类实例的行出现编译错误】
2、单选题:
有关内嵌类以下哪个叙述为假?
选项:
A: 内嵌类可以访问外部类的成员
B: 方法中的内嵌类可以访问方法中定义的常量
C: 匿名内嵌类没有对应的字节码文件
D: 内嵌类可以被定义为静态成员
答案: 【 匿名内嵌类没有对应的字节码文件】
3、单选题:
以下程序的编译和运行结果为?abstract class Base{ abstract public void myfunc(); public void another(){ System.out.println("Another method"); }}public class Abs extends Base{ public static void main(String argv[]){ Abs a = new Abs(); a.amethod(); } public void myfunc(){ System.out.println("My Func"); } public void amethod(){ myfunc(); }}
选项:
A: 输出结果为 My Func
B: 编译指示 Base 类中存在抽象方法
C: 编译通过,但运行时指示Base 类中存在抽象方法
D: 编译指示Base 类中的myfunc方法无方法体,没谁会喜欢该方法。
答案: 【 输出结果为 My Func】
4、单选题:
以下代码的调试结果为?abstract class MineBase { abstract void amethod(); static int i;}public class Mine extends MineBase{ public static void main(String argv[]){ int[] ar = new int[5]; for(i = 0;i < ar.length;i++) System.out.println(ar[i]); }}
选项:
A: 输出5个0
B: 编译错误指示"ar 未初始化就使用"
C: 编译错误指示"Mine 必须定义为抽象类"
D: 运行错误, i超出数组下标范围
答案: 【 编译错误指示"Mine 必须定义为抽象类"】
5、多选题:
设有类定义如下:class InOut{ String s = new String("Between"); public void amethod(final int iArgs){ int iam = 5; iam++; class Bicycle{ &
