当前位置: 代码迷 >> Java面试 >> java面试题3两题
  详细解决方案

java面试题3两题

热度:26   发布时间:2016-04-17 18:24:27.0
java面试题三两题
Java代码  1.public static void main(String[] args) throws Exception {   2.    int[] x = new int[6];   3.    Arrays.fill(x, 1);   4.    for (int i = 0; i < x.length; i++) {   5.        System.in.read();   6.        System.out.println(x[i]);   7.    }   8.}  public static void main(String[] args) throws Exception { int[] x = new int[6]; Arrays.fill(x, 1); for (int i = 0; i < x.length; i++) { System.in.read(); System.out.println(x[i]); } }这段代码,输入“1”(不含引号),按回车后,系统输出什么? 
?
第二题:
Java代码  1.private static void foo() {   2.    try {   3.        System.out.println("try");   4.        foo();   5.    } catch (Throwable e) {   6.        System.out.println("catch");   7.        foo();   8.    } finally {   9.        System.out.println("finally");   10.        foo();   11.    }   12.}   13.  14.public static void main(String[] args) {   15.    foo();   16.}  private static void foo() { try { System.out.println("try"); foo(); } catch (Throwable e) { System.out.println("catch"); foo(); } finally { System.out.println("finally"); foo(); } } public static void main(String[] args) { foo(); }
?
上述代码运行后:
A.执行一段时间后报栈溢出。?? B.会一直输出“try”。??? C.会一直输出“try”和“finally”。??? D.会一直输出“try”、“catch”和“finally”

第三题:
Java代码  1.A = 1;   2.System.out.println(A);  
?
A是一个int类型变量,请在这段代码的前、后添加任意代码(但两句之间不能再插入代码),使得程序编译时第一句可以编译通过,而第二句出现编译错误。
另:请不要以“脑筋急转弯”的方式来思考此问题,这里java就是普通的java语言,rt.jar和javac都没有被修改过。打印语句import的就是我们平常所用的打印语句。
原文来源:watertap

?

  相关解决方案