异常处理

异常处理单元测验

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(String  i) { }
答案: 【  public void amethod(int i)  { };
public void amethod(long i)  { };
public void amethod(String  i) { }

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、单选题:
‎一个 int 类型的整数和一个 double 类型的数进行加法运算,则结果类型为‎
选项:
A: int 
B: double
C: float
D: long
答案: 【 double

2、单选题:
​有关内嵌类以下哪个叙述为假?‏
选项:
A: 内嵌类可以访问外部类的成员
B: 方法中的内嵌类可以访问方法中定义的常量
C: 匿名内嵌类没有对应的字节码文件
D: 内嵌类可以被定义为静态成员
答案: 【 匿名内嵌类没有对应的字节码文件

3、单选题:
‌若在某一个类定义中定义有如下的方法: abstract  void  performDial( ); 该方法属于?​
选项:
A: 本地方法
B: 最终方法
C: 多态方法
D: 抽象方法
答案: 【 抽象方法

4、单选题:
类Test1定义如下:‌1.public  class  Test1{‌2.     public  float  aMethod(float  a,float  b){   }‌3.      ‌4.}‌下面方法中插入行3处为不合法的是(      )。‌‎‌
选项:
A: public  float  aMethod(float  a, float  b,float  c){  }
B: public  float  aMethod(float  c,float d){  }
C: public  int  aMethod(int  a, int b){  }
D: private float  aMethod(int a,int b,int c){  }
答案: 【 public  float  aMethod(float  c,float d){  }

5、单选题:
​int型public成员变量MAX_LENGTH,该值保持为常数100,则定义这个变量的语句是‍
选项:
A: public int MAX_LENGTH=100;
B: final int MAX_LENGTH=100;
C: public final int MAX_LENGTH=100;
D: public const int MAX_LENGTH=100;
答案: 【 public final int MAX_LENGTH=100;

6、单选题:
为了使下面的程序能通过编译,最少要做的修改是(      )。‍1.  final class A {‍2.     int x;‍3.     void mA() { x=x+1; }‍4.  }‍5.  class B extends A {‍6.     final A a=new A();‍7.     final void mB(){‍8.        a.x=20;‍9.        System.out.println("hello");‍10.    }‍11.  }‍‍‍
选项:
A: 第1行去掉final
B: 第6行去掉final
C: 删除第8行
D: 行1和行6去掉final
答案: 【 第1行去掉final

7、单选题:
以下程序调试结果为(      )。‌public class Test {    int m = 5;    public void some(int x) {        m = x;    }    public static void main(String args[ ]) {      new Demo().some(7);    }}class Demo extends Test {    int m = 8;    public void some(int x) {        super.some(x);        System.out.println(m);    }}‌‎‌
选项:
A: 5
B: 8
C: 7
D: 无任何输出
答案: 【 8

8、单选题:
考虑如下类: ‌public class Test {‌   public static void test() {‌       this.print();‌   }‌   public static void print() {‌       System.out.println("Test");‌   }‌   public static void main(String args []) {‌       test();‌   }‌} ‌则程序调试结果为?‌‍‌
选项:
A: 输出Test 
B: 无输出结果. 
C: 编译错误,不能在静态上下文环境中引用 this
D: 无构造方法,不能创建对象
答案: 【 编译错误,不能在静态上下文环境中引用 this

9、单选题:
运行下列代码后,正确的结果为: ​public class Test {​static int age;​public static void main (String args []) {​age = age + 1;​System.out.println("age=" + age);​}​}​‎​
选项:
A: 编译运行后无任何输出
B: 编译运行后输出 age=1
C: 编译运行后输出 age=0
D: 编译出错
答案: 【 编译运行后输出 age=1

10、单选题:
给出如下不完整类:‌class Person { ‌     String name, department; ‌     int age; ‌    public Person(String n){ name = n; } ‌    public Person(String n, int a){ name = n; age = a; } ‌    public Person(String n, String d, int a){ ‌            //给属性 name,age 赋值,比如:name=n;age=a;‌           department = d; ‌    } ‌} ‌可取代注释部分位置内容达到注释的目标的是( )。‌‍‌
选项:
A: Person(n,a); 
B: this(Person(n,a)); 
C: this(n,a); 
D: this(name,age);
答案: 【 this(n,a); 

11、单选题:
以下代码的输出结果为( )。‍public class Test{‍   int x=5;‍   public static void main(String argv[ ]){‍       Test t=new Test();‍       t.x++;‍       change(t); ‍       System.out.println(t.x);‍   }‍   static void change(Test m){‍       m.x+=2;‍    }‍}‍‌‍
选项:
A: 7
B: 6
C: 5
D: 8
答案: 【 8

12、单选题:
下列语句片段的结果为: ​  int result; ​  int a = 17, b = 6; ​  result = (a % b > 4)? a % b : a / b ;​  System,out.println(result); ​‌​
选项:
A: 0
B: 1
C: 2
D: 5
答案: 【 5

13、单选题:
下面的代码段的输出结果为?‍    int count = 0;‍    for (int i = 1; i < 4; i++) ‍         count += i;‍    System.out.println(count);‍‌‍
选项:
A: 4
B: 1
C: 6
D: 10
答案: 【 6

14、单选题:
若a的值为3时,下列程序段被执行后,c的值是多少?‌int c = 1;‌if  ( a>0 )‌if  ( a>3 )‌c = 2;‌else‌c = 3;‌else‌c = 4;‌​‌
选项:
A: 2
B: 3
C: 1
D: 4
答案: 【 3

15、单选题:
执行以下程序后,输出结果为( )。‏public class Ex2{‏     public static void main(String args[ ]) {‏           int k ,f=1;‏           for (k=2;k<5;k++)‏                 f = f * k;‏           System.out.println(k); ‏     }‏}‏​‏
选项:
A: 1
B: 4
C: 5
D: 24
答案: 【 5

16、单选题:
‎利用Scanner对象从输入数据源获取一个整数的方法是?‎
选项:
A: next()
B: nextInt()
C: nextLine()
D: nextDouble()
答案: 【 nextInt()

17、单选题:
‌以下数据类型转换中,必须进行强制类型转换的是‎
选项:
A: int→char
B: short→long
C: float→double
D: int→double
答案: 【 int→char

18、单选题:
‏下列叙述中,正确的是?‎
选项:
A: 声明变量时必须指定一个类型
B: java认为变量number与Number相同
C: Java中唯一的注释方式是"//"
D: 一个源文件中public类可以有0或多个
答案: 【 声明变量时必须指定一个类型

19、单选题:
整型变量a,b的值定义如下:‎    int a = 21;‎    int b = 22;‎则表达式 ++a == b++ 的值为:‎‎‎
选项:
A: false
B: 21
C: true
D: 22
答案: 【 true

20、单选题:
‍表达式 1+2+ "x"+3 的值是‌
选项:

剩余75%内容付费后可查看

发表评论

电子邮件地址不会被公开。 必填项已用*标注