设为首页 加入收藏

TOP

Java基础知识面试题异常相关的选择题
2014-11-24 01:43:19 来源: 作者: 【 】 浏览:10
Tags:Java 基础 知识面 试题 异常 相关 选择

1. 阅读如下的程序代码:
public class ExceptionTest{
public double div(double a, double b){
try{
return a/b;
}catch(Exception e){
System.out.println(“Exception thrown”);
}finally{
System.out.println(“Release resources.”);
}
}
public static void main(String[] args){
ExceptionTest et = new ExceptionTest();
et.div(1, 2);
et.div(3.4, 0);
}
}
以上代码可能产生的结果是:( )
 A 编译不成功
 B 无法运行
 C 程序运行输出为:
 Release resources.
 Exception thrown.
 Release resources.


2. unchecked exception又叫:( )
A RuntimeException
B Exception
C Error
D throw


3. Checked Exception通常继承:( )
A RuntimeException
B Exception
C Error
D throw


4. 在方法签名上指定可能有异常产生用关键字:( )
A Exception
B throw
C throws
D printStackTrace


5. 获得异常的简单描述信息调用方法是:( )
A getMessage
B throw
C throws
D printStackTrace


6. 运行下面的代码,结果是什么?( )
public class Test{
 public static void main(String[] args){
 try{
return;
  }finally{
System.out.println(“Finally”);
 }
 }
}
A 什么都不输出
B 输出”Finally”
C 编译错误
D 以上选择都不对


7. 如下的代码:
public class Test{
  public static void main(String[] args){
  String foo=args[1];
  String bar=args[2];
  String baz=args[3];
  System.out.println(baz)
  }
}
运行命令:java Test Red Green Blue,输出什么结果:( )
A “”
B null
C “Red”
D “Blue”
E “Green”
F 这段代码不能被编译
G 抛出异常


8. 看下面的代码:
int index=1;
int foo=new int[3];
int bar=foo[index];
int baz=bar+index;
System.out.println(baz);
运行结果是什么?( )
A 输出0
B 输出1
C 输出2
D 抛出一个异常
E 代码不能被编译


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇华为北京笔试经历-2012年7月 下一篇网上流传的C++面试题

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: