JAVA面试题(1)

1.新建一个流对象,下面哪个选项的代码是错误的?(B )

A)new BufferedWriter(new FileWriter("a.txt")); 
B)new BufferedReader(new FileInputStream("a.dat")); 
C)new GZIPOutputStream(new FileOutputStream("a.zip")); 
D)new ObjectInputStream(new FileInputStream("a.dat"));

2.getCustomerInfo()方法如下,try中可以捕获三种类型的异常,如果在该方法运行中产生了一个IOException,将会输出什么结果(A)

public void getCustomerInfo() {
  try { 
    // do something that may cause an Exception 
  } catch (java.io.FileNotFoundExceptionex){ 
    System.out.print("FileNotFoundException!"); 
  } catch (java.io.IOExceptionex){ 
    System.out.print("IOException!"); 
  } catch (java.lang.Exceptionex){ 
    System.out.print("Exception!"); 
  }
} 

A)IOException!  

B)IOException!Exception!  

C)FileNotFoundException!IOException! 

D)FileNotFoundException!IOException!Exception!

3. 下面代码的运行结果为:(C)
import java.io.*; import java.util.*; public class foo{ public static void main (String[] args){ String s; System.out.println("s=" + s); } }

A 代码得到编译,并输出“s=”

B 代码得到编译,并输出“s=null”

C 由于String s没有初始化,代码不能编译通过

D 代码得到编译,但捕获到 NullPointException异常

4.指出下列程序运行的结果 (B)

public class Example {

String str = new String("good");

char[] ch = { 'a', 'b', 'c' };

public static void main(String args[]) {

Example ex = new Example();

ex.change(ex.str, ex.ch);

System.out.print(ex.str + " and ");

System.out.print(ex.ch);

}

public void change(String str, char ch[]) {

str = "test ok";

ch[0] = 'g';

}
}

A、 good and abc

B、 good and gbc

C、 test ok and abc

D、 test ok and gbc 

转载于:https://www.cnblogs.com/zyjava/p/4346379.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值