码迷,mamicode.com
首页 > 编程语言 > 详细

JAVA面试题(1)

时间:2015-03-18 10:22:29      阅读:248      评论:0      收藏:0      [点我收藏+]

标签:

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 

JAVA面试题(1)

标签:

原文地址:http://www.cnblogs.com/zyjava/p/4346379.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!